I am using a form to upload video files. For some reason all I get is the following error:
Symfony \\ Component \\ HttpFoundation \\ File \\ Exception \\ Fil
In 2020 with Laravel 5.8, I discovered this problem and your answers gave me clues, but I was still getting an error when I tried the isValid
method. I found this was the best way to check if a file was too large:
$file_result = new \stdClass();
if ($request->file('file_to_upload')->getSize() === false) {
$max_upload = min(ini_get('post_max_size'), ini_get('upload_max_filesize'));
//From: https://gist.github.com/svizion/2343619
$max_upload = str_replace('M', '', $max_upload);
$max_upload = $max_upload * 1024;
$file_result->error = "The file you are trying to upload is too large. The maximum size is " . $max_upload;
//return whatever json_encoded data your client-side app expects.
}
It looks as if the getSize
method successfully returns false if the file size exceeds the maximum size. In my experience isValid
throws an obscure error. The upload_max_filesize parameter is there to protect the server so I wanted a reliable way of catching when the user attempts to upload a large file and my client-side validation is not set correctly.