Laravel Multiple Validator Error Report

Problem: if the downloaded file exceeds 5000 kb, the validator returns the message "required" instead of the message "max". 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 issue is especially important for checking * .psd files.


Update 2: when I var_dump ($ file), I see this:

 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 path name and file_name look null. So why laravel returns the requested message. Here's a new question: why is file_name null?

+4
source share
1 answer

When you upload a file larger than the allowed size (maximum message size and maximum upload size), php does not send it to the server, so your code does not receive the file and with the error required.

go to your php.ini and increase the maximum download size and maximum message size. this should solve your problem.

you can also install them in php:

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

or you can edit the php.ini file for them:

 post_max_size = 64M upload_max_filesize = 64M 
+4
source

All Articles