简体   繁体   English

Symfony2大文件上传

[英]Symfony2 Large File Uploads

I am trying to upload large files (5-8Mb) in my Symfony2 projects. 我正在尝试在Symfony2项目中上传大文件(5-8Mb)。 For some reason anytime I upload anything larger than 2Mb the script bombs out. 由于某种原因,无论何时我上传大于2Mb的内容,脚本都会炸毁。 I can upload anything smaller than 2Mb. 我可以上传小于2Mb的任何内容。 I have changed my php.ini file and php -i reflects these changes. 我已经更改了php.ini文件,而php -i反映了这些更改。 I have restarted apache. 我已经重新启动了Apache。 What else do i need to do to make these larger file upload work. 为了使这些较大的文件上载工作,我还需要做什么。 Thanks. 谢谢。

Ran into this issue before; 之前遇到过这个问题; try a chunking method of uploading. 尝试上传的分块方法。 Most likely the script is exceeding the max execution time. 该脚本很可能超过了最大执行时间。 So (without knowing what your logic looks like) have a function that sends the request (say 1MB) to another file that reads the input stream of the binary data within a while loop and continues to execute as long as the content length of the binary data does not equal zero. 因此(不知道您的逻辑是什么样)具有一个将请求(例如1MB)发送到另一个文件的功能,该文件在while循环内读取二进制数据的输入流,并且只要二进制文件的内容长度就可以继续执行数据不等于零。 The while loop writes the data to a temp file and when it hits zero saves it to a permanent directory (or whatever you want to do from there) You can increase the max memory allowed and execution time in php.ini but this introduces security issues and is not recommended. while循环将数据写入临时文件,当它为零时将其保存到永久目录(或您要从那里执行的任何操作)。您可以在php.ini中增加允许的最大内存和执行时间,但这会带来安全性问题并且不推荐。

In your current PHP config, you probably limited the max upload size to 2M, so Symfony display the wrong error. 在当前的PHP配置中,您可能将最大上传大小限制为2M,因此Symfony显示错误错误。

So check your php.ini file (/etc/php5/apache2/php.ini on Linux) and increase max_upload_size to fit your field : 因此,请检查您的php.ini文件(在Linux上为/etc/php5/apache2/php.ini),并增加max_upload_size以适合您的领域:

upload_max_filesize = 20M upload_max_filesize = 20M

Don't forget to restart apache : apache2ctl restart 不要忘记重启apache:apache2ctl restart

Now it should work ! 现在应该可以了!

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

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