last day (14 days later) » 

4:50 AM
0
A: Laravel - How validate max size of an image that exceed upload_max_filesize directive

mdamiaYou need to use size instead of max to validate file size. max:value Blockquote The field under validation must be less than or equal to a maximum value. Strings, numerics, and files are evaluated in the same fashion as the size rule So we go to the Size rule: size:value Blockquote ...

 
the correct rule to this case is max:value, but look to my problem: i can't access size value of uploaded whenever the file exceed the directive value. How i'll validate?
 
@AlexandreThebaldi I updated my answer, just adapt it to your scenario and it should work.
 
file with less then upload_max_filesize directive: Input::file('avatar')->getSize() // 900498
file greater then upload_max_filesize directive: Input::file('avatar')->getSize() // false
 
where are you setting that directive?
 
as default, at php.ini, upload_max_filesize = 2MB
 
4:50 AM
if you want to do server validation you will need to change the value to get the file size, also set post_max_size as well. Or you can check if the value == false return error.
 
You are touching at the core of my problem: i don't wanna change default value and image is optional, so, if Request::hasFile('avatar') == false i should not return an error
Now, in my position, i'm not able to send a feedback to user from the server for size exceeding max size
hi
 
Hey
I would recommend the later, if error do nothing since the image is optional.
better approach.
 
dude, i'm a little bit curious about this because at last night was working fine
 
What did you change since last night?
 
nothing at php, only js but nothing much important
only add some client validations
 
4:58 AM
does your app crashes when you upload a large file?
 
no
look to my other question about this (has more information)
1
Q: Laravel - Validation max rule not working on uploaded image

Alexandre ThebaldiI'm handling a file field with ajax request (FormData) to send an image to server. Here is my php ajax handler public function onUploadAvatar() { $photo = Request::file('avatar'); $avatar = new Controllers\AvatarController( $photo ); $validator = $avatar->validator(); if ( $validator->fails(...

 
but you don't want to change upload_max_filesize ? if I am not mistaken?
 

last day (14 days later) »