简体   繁体   English

Laravel上传大文件时出错

[英]Laravel getting error while uploading large file

I am trying to upload software installation file (.exe) in my site.When I am trying to upload file like 5 mb or 10 mb, I don't get any error.But while trying to upload large file,size of 45/50mb,I am getting this error 我正在尝试在网站上上传软件安装文件(.exe)。当我尝试上传5 mb或10 mb之类的文件时,我没有收到任何错误。但是在尝试上传45 / 50mb,我收到此错误

(1/1) FatalThrowableError

Call to a member function getClientOriginalExtension() on null

I have changed my php.ini like this: 我已经这样更改了php.ini:

upload_max_filesize = 900M

Here is my file upload form 这是我的文件上传表格

<form action="/upload" method="post" enctype="multipart/form-data">
    {{ csrf_field() }}
    Product name:
    <br />
    <input type="text" name="name" />
    <br /><br />
    Files :
    <br />
    <input type="file" name="pdf" multiple />
    <br /><br />
    <input type="submit" value="Upload" />
</form>

Here is my controller: 这是我的控制器:

public function google(Request $request){

            $file = $request->file('pdf');
            $destinationPath = 'uploads';
            $file->move($destinationPath,$file->getClientOriginalName());

}

Update: 更新:

I have increased post_max_size greater than upload_max_filesize .But now getting this error 我增加的post_max_size大于upload_max_filesize但是现在出现此错误

(1/1) FatalErrorException
Allowed memory size of 134217728 bytes exhausted (tried to allocate 62973720 bytes)
in MediaFileUpload.php (line 246)

Default php.ini memory_limit is 128 MB. 默认php.ini memory_limit为128 MB。 You should either: 您应该:

  • Optimize your code to use a normal amount of data 优化您的代码以使用正常数量的数据
  • change memory_limit in php.ini to higher value which I do not recommend at all - with your approach you will hit this wall once again 将php.ini中的memory_limit更改为更高的值,我根本不建议这样做-使用您的方法,您将再次碰壁

You should refer to this answer . 您应该参考此答案 I would recommend you monitor your application and see if there is a potential memory leak and optimize your code. 我建议您监视应用程序,看看是否存在潜在的内存泄漏并优化代码。

One of the key things you need to remember with standard file uploading, is that your server needs to handle the file, hints why it takes up a lot of memory. 使用标准文件上传时,需要记住的关键事项之一是服务器需要处理文件,这暗示了为什么占用大量内存。

Hopefully that helps you on the right path. 希望这可以帮助您走上正确的道路。

在php.ini中增加'memory_limit'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM