5

Problem : When uploaded file exceeds 5000kb, validator returns the 'required' message instead of 'max' message. Why ?

$file = (Input::file('inputName'));
$fileValidator = Validator::make(
   array('Field Name' => $file),
   array('Field Name' => 'required|max:5000|mimes:jpeg,png,bmp')
);

if($fileValidator->fails()){
   return $fileValidator->errors()->all(':message');
}

Update : This problem occurs especially *.psd files' validation.


Update 2 : when i var_dump($file), i can see that;

object(Symfony\Component\HttpFoundation\File\UploadedFile)#9 (7) {
  ["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
  bool(false)
  ["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
  string(52) "4-47970_rsasecurityanalyticsevolutionofsiemebook.pdf"
  ["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
  string(24) "application/octet-stream"
  ["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
  int(0)
  ["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
  int(1)
  ["pathName":"SplFileInfo":private]=>
  string(0) ""
  ["fileName":"SplFileInfo":private]=>
  string(0) ""
}

As you can see, the pathName and fileName looks null. So that's why laravel returns required message. Here's the new question : why is the fileName is null ?

9
  • Please can you replace Field Name with actual field name you name in the form Commented Aug 10, 2015 at 7:09
  • @Digitlimit i already changed it. Commented Aug 10, 2015 at 7:10
  • can you do dd(Input::file('inputName')); just to confirm the file was submitted? Commented Aug 10, 2015 at 7:14
  • @Digitlimit, it is confirmed, file is submitted, can get its values with var_dump(Input::file('inputName')). also gets the mime type as like following : application/pdf, image/png etc. Commented Aug 10, 2015 at 7:16
  • how about including psd in mimes type like so: mimes:jpeg,png,bmp,psd Commented Aug 10, 2015 at 7:22

1 Answer 1

4

When you upload a file more than the allowed size (max post size and max upload size), then php does not send it to the server, that is why your code does not get file and through an error of required.

go to your php.ini and increase the limit of max upload and max post size. this should solve your issue.

you can also set these by php:

ini_set('post_max_size', '64M');
ini_set('upload_max_filesize', '64M');

or you can edit your php.ini file for these:

post_max_size = 64M
upload_max_filesize = 64M
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.