php PHP如何上传500MB以上的大文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16102809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to upload large files above 500MB in PHP
提问by James Okpe George
I made an upload page in PHP, but I dont know why the page would not upload documents greater than 500MB, This is my first time of trying to upload something that large, I changed all the configurations in the PHP.INI (post_max_size = 700M, upload_max_filesize = 600M, and max_execution_time = 300). The codes for upload is as below
我用PHP做了一个上传页面,但是我不知道为什么页面不会上传大于500MB的文件,这是我第一次尝试上传这么大的东西,我改变了PHP.INI中的所有配置(post_max_size = 700M ,upload_max_filesize = 600M,max_execution_time = 300)。上传代码如下
if(isset($_FILES['upload']) && !empty($_FILES['upload']['name'])){
move_uploaded_file($_FILES['upload']['tmp_name'], $this->filePath.$this->fileName);
}
I need help, I wonder if there is something am not doing right..
我需要帮助,我想知道是否有什么地方做得不对..
采纳答案by Twisted1919
Do you think if increasing upload size limit will solve the problem? what if uploading 2GB file, what's happening then? Do you take into consideration the memory usage of such a script?
您认为增加上传大小限制是否可以解决问题?如果上传 2GB 文件,会发生什么?您是否考虑过此类脚本的内存使用情况?
Instead, what you need is chunked upload, see here : Handling plupload's chunked uploads on the server-sideand here : File uploads; How to utilize "chunking"?
相反,您需要的是分块上传,请参见此处:在服务器端处理 plupload 的分块上传和此处:文件上传;如何利用“分块”?
回答by Jean
By configuration, PHP only allows to upload files up to a certain size. There are lots of articles around the web that explain how to modify this limit. Below are a few of them:
通过配置,PHP 只允许上传一定大小的文件。网络上有很多文章解释了如何修改此限制。以下是其中一些:
- PHP Increase Upload File Size Limit
- How do I increase the PHP upload limits?
- Uploading large(big) files in PHP using .htaccess
For instance, you can edit your php.ini
file and set:
例如,您可以编辑php.ini
文件并设置:
memory_limit = 32M
upload_max_filesize = 24M
post_max_size = 32M
You will then need to restart apache.
然后您将需要重新启动 apache。
Note:
That being said, Uploading large files like that is not very reliable. Errors can occur. You may want to split the files, and include some additional data for error corrections. One way to do that is to use par recovery files. You can then check the files after upload using the par
command line utilityon unix-like systems.
注意:话
虽如此,像这样上传大文件并不是很可靠。可能会发生错误。您可能希望拆分文件,并包含一些用于纠错的附加数据。一种方法是使用标准恢复文件。然后,您可以在类 Unix 系统上使用par
命令行实用程序在上传后检查文件。
回答by Suresh Kumar Amrani
I assume you mean that you transferring the files via HTTP. While not quite as bad as FTP, its not a good idea if you can find another of solving the problem. HTTP (and hence the component programs) are optimized around transferring relatively small files around the internet.
我假设您的意思是通过 HTTP 传输文件。虽然不像 FTP 那样糟糕,但如果你能找到另一个解决问题的方法,这不是一个好主意。HTTP(以及组件程序)针对在 Internet 上传输相对较小的文件进行了优化。
While the protocol supports server to client range requests, it does not allow for the reverse operation. Even if the software at either end were unaffected by the volume, the more data you are pushing across the greater the interval during which you could lose the connection. But the biggest problem is that caveat in the last sentence.
虽然该协议支持服务器到客户端范围的请求,但它不允许反向操作。即使两端的软件不受卷的影响,您推送的数据越多,您可能会失去连接的时间间隔就越大。但最大的问题是最后一句中的警告。