Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel file does not exist - file upload

I am using a form to upload video files. For some reason all I get is the following error:

Symfony \ Component \ HttpFoundation \ File \ Exception \ FileNotFoundException
The file "" does not exist

In my controller I had a validation rule to require files, like so

$validator = Validator::make(Input::all(),
  array(
    'file'  => 'required'
  )
);

But because of the above rule, I couldn't properly debug what is going on, therefore I ended up removing it, as a result to generate the above error.

like image 245
cch Avatar asked Mar 13 '14 19:03

cch


People also ask

What is not uploaded due to an unknown error in laravel?

Check your code if your file upload code is running two times. You can check this part of the code. Make sure you type it correctly and not repeat it twice.


1 Answers

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.

like image 129
DavidHyogo Avatar answered Sep 28 '22 05:09

DavidHyogo