Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel file upload validation doesn't trigger - TokenMismatchException

I can upload the files if they are fitting this validation rule

'user_file' => 'file|max:10240|mimes:xls,xlsx,doc,docx,pdf,zip'

all goes fine.

I have set my upload_max_filesize to 32MB and post_max_size to 40MB in php.ini

but if i try to upload a file bigger than 40MB my validation rules don't even trigger. I get TokenMismatchException error....

If someone can verify this by simply trying to upload some very big file (a video file for example)

like image 465
lewis4u Avatar asked Nov 22 '25 09:11

lewis4u


1 Answers

When You exceed post payload size - everything is dropped, so csrf_token does not come to laravel and the upload file is empty so it cannot be validated.

UPDATE

To fix this you need to check the file size before the uploading with javascript or jquery

here is an example:

How to check file input size with jQuery?

like image 179
Giedrius Kiršys Avatar answered Nov 23 '25 23:11

Giedrius Kiršys



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!