lewis4u lewis4u - 1 year ago 147
PHP Question

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)

Answer Source

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.


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?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download