Laravel file does not exist - file upload

前端 未结 4 700
臣服心动
臣服心动 2020-12-31 11:50

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         


        
相关标签:
4条回答
  • 2020-12-31 12:14

    To clear the answer The problem that you uploaded file which size is more than php configuration located in php.ini, so when you try to access the any property of the uploadFile object you will see the exception because file not exist

    0 讨论(0)
  • 2020-12-31 12:15

    In the php.ini file, change the following:

    upload_max_filesize = 20M
    post_max_size = 20M
    

    This should make it work.

    0 讨论(0)
  • 2020-12-31 12:22

    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.

    0 讨论(0)
  • 2020-12-31 12:34

    Probably the problem is the "upload_max_filesize" that has been exceeded (check your php.ini), however it is a good practice to first check if the file is valid.

    if (!$file->isValid()) {
        throw new \Exception('Error on upload file: '.$file->getErrorMessage());
    }
    //...
    
    0 讨论(0)
提交回复
热议问题