Tag Archives: Laravel Upload Files Verificate Error

[Solved] Laravel Upload Files Verificate Error: The file failed to upload.

Cause of error

This is the verification code I wrote based on the verification component of laravel:

In most cases, it is normal, but when the front end uploads pictures, it occasionally reports the inexplicable error of the file failed to upload. You know, there is no prompt about this error in my code. After many investigations, it can be basically determined that the error is caused by the size of the picture.

First of all, the size of the uploaded file configured by PHP by default is 2m, which can be found in PHP.ini configuration file;

upload_max_filesize=2M
post_max_size=8M

Secondly, the size limit in my laravle validation is also 2M, and laravel by default internally calls the validation based on the configuration of php, so this validation I made did not take effect at all, and the error reported was also called internally by the laravel framework.

The 422 exception thrown by the system function form validation class: The file failed to upload. and by looking at the resources/lang/en/validation file we can see that the actual framework layer is calling the uploaded validation.

Solution:

After modifying the php default configuration and changing the upload image limit size, the image upload problem was successfully solved, I changed it to 20M here, you can modify it according to the actual situation of the project.

upload_max_filesize=20M
post_max_size=20M