Created
November 24, 2014 23:47
-
-
Save eseyden/711181a25cc3b20e27ac to your computer and use it in GitHub Desktop.
Fix Laravel Upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace ACME\Validation; | |
use Illuminate\Validation\Factory as LaravelFactory; | |
class Factory extends LaravelFactory{ | |
/** | |
* Resolve a new Validator instance. | |
* | |
* @param array $data | |
* @param array $rules | |
* @param array $messages | |
* @param array $customAttributes | |
* @return \Illuminate\Validation\Validator | |
*/ | |
protected function resolve(array $data, array $rules, array $messages, array $customAttributes) | |
{ | |
if (is_null($this->resolver)) | |
{ | |
return new Validator($this->translator, $data, $rules, $messages, $customAttributes); | |
} | |
else | |
{ | |
return call_user_func($this->resolver, $this->translator, $data, $rules, $messages, $customAttributes); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace ACME\Validation; | |
use Illuminate\Validation\ValidationServiceProvider as LaravelValidationServiceProvider; | |
class ValidationServiceProvider extends LaravelValidationServiceProvider { | |
/** | |
* Indicates if loading of the provider is deferred. | |
* | |
* @var bool | |
*/ | |
protected $defer = true; | |
/** | |
* Register the service provider. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
$this->registerPresenceVerifier(); | |
$this->app->bindShared('validator', function($app) | |
{ | |
$validator = new Factory($app['translator'], $app); | |
// The validation presence verifier is responsible for determining the existence | |
// of values in a given data collection, typically a relational database or | |
// other persistent data stores. And it is used to check for uniqueness. | |
if (isset($app['validation.presence'])) | |
{ | |
$validator->setPresenceVerifier($app['validation.presence']); | |
} | |
return $validator; | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace ACME\Validation; | |
use Illuminate\Validation\Validator as LaravelValidator; | |
use Symfony\Component\HttpFoundation\File\File; | |
class Validator extends LaravelValidator{ | |
/** | |
* Validate the MIME type of a file upload attribute is in a set of MIME types. | |
* | |
* @param string $attribute | |
* @param array $value | |
* @param array $parameters | |
* @return bool | |
*/ | |
protected function validateMimes($attribute, $value, $parameters) | |
{ | |
if ( ! $value instanceof File) | |
{ | |
return false; | |
} | |
// The Symfony File class should do a decent job of guessing the extension | |
// based on the true MIME type so we'll just loop through the array of | |
// extensions and compare it to the guessed extension of the files. | |
if ($value->isValid() && $value->getPath() != '') | |
{ | |
//CHANGED FROM $value->guessExtension() | |
return in_array($value->guessClientExtension(), $parameters); | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment