无法在Laravel中上传大文件(我认为php.ini设置正确) [英] Can't upload large file in Laravel (php.ini settings are correct in my opinion)

查看:46
本文介绍了无法在Laravel中上传大文件(我认为php.ini设置正确)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Laravel中遇到以下问题.

I have the following problem in Laravel.

我想通过表格上传文件.但是由于某种原因,如果文件大于2100 KB,则验证失败,并说该文件是必需的",而我没有提供.

I would like to upload a file through a form. But for some reason if the file is larger than around 2100 KB, the validation fails, and says that the file is 'required' and I did not provide it.

我已经阅读了许多文章,这可能是由于php.ini设置所致.在我的服务器上,它们是:

I've read numerous articles, that this can be because of php.ini settings. On my server they are the following:

upload_max_filesize 64M
post_max_size 64M

这些值是从phpinfo()的输出中复制的,因此它们有效.

These values are copied from the output of phpinfo(), so they are in effect.

尽管如此,即使对于2 MB的文件,上传也失败.您有什么想法可以检查/设置以解决此问题吗?

And despite this, the upload fails even for a 2 MB file. Do you have any ideas what I could check/set to solve this?

我正在使用laravel 5.2和PHP7.

I am using laravel 5.2, and PHP 7.

推荐答案

检查所使用的服务器软件.例如,Nginx有它自己的限制(我相信默认设置为1MB). Apache可能也有.有关这些程序包的配置方法,请查阅相应的手册.或者,如果您使用共享主机,请与支持人员联系以查看它们是否可以增加限制.

Check which server software you are using. Nginx for instance has it's own limit (default set to 1MB I believe). Apache might have it too. Consult the respective manuals for those packages on how to configure them. Or if you're using shared hosting, contact support to see if they can increase the limit.

尽管这不是一个真正可扩展的解决方案.下次您可能要上载100MB的文件,并且可能不想在服务器上允许100MB的请求.更好的方法是使用JavaScript在前端将文件拆分为较小的块,然后将其作为同一上传的一部分提交,然后在文件完全上传之后在服务器上重新组合这些部分.不过要提防其他检查.

Though this isn't a really scalable solution. Next time you might want to upload a 100MB file, and you probably don't want to allow 100MB requests on your servers. A better approach would be to split the file in smaller chunks in the frontend, with JavaScript, and submit them as parts of the same upload, then recombine the parts on the server once the file is completely uploaded. Beware of additional checks you'll have to do here though.

这篇关于无法在Laravel中上传大文件(我认为php.ini设置正确)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆