如何在PHP中上传500MB以上的大文件[重复]

时间:2023-01-24 11:37:11

This question already has an answer here:

这个问题在这里已有答案:

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..

我需要帮助,我想知道是否有些事情做得不对..

3 个解决方案

#1


16  

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-side and here : File uploads; How to utilize "chunking"?

相反,您需要的是分块上传,请参阅此处:在服务器端和此处处理plupload的分块上传:文件上传;如何利用“分块”?

#2


9  

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只允许上传一定大小的文件。网上有很多文章解释了如何修改这个限制。以下是其中一些:

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 utility on unix-like systems.

注意:话虽如此,上传像这样的大文件并不是很可靠。可能会发生错误。您可能希望拆分文件,并包含一些其他数据以进行错误更正。一种方法是使用par恢复文件。然后,您可以在类似unix的系统上使用par命令行实用程序检查上载后的文件。

#3


0  

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(以及组件程序)围绕在互联网上传输相对较小的文件进行了优化。

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.

虽然协议支持服务器到客户端范围请求,但它不允许反向操作。即使两端的软件不受卷的影响,您推送的数据越多,可能会丢失连接的时间间隔越大。但最大的问题是最后一句中的警告。

#1


16  

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-side and here : File uploads; How to utilize "chunking"?

相反,您需要的是分块上传,请参阅此处:在服务器端和此处处理plupload的分块上传:文件上传;如何利用“分块”?

#2


9  

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只允许上传一定大小的文件。网上有很多文章解释了如何修改这个限制。以下是其中一些:

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 utility on unix-like systems.

注意:话虽如此,上传像这样的大文件并不是很可靠。可能会发生错误。您可能希望拆分文件,并包含一些其他数据以进行错误更正。一种方法是使用par恢复文件。然后,您可以在类似unix的系统上使用par命令行实用程序检查上载后的文件。

#3


0  

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(以及组件程序)围绕在互联网上传输相对较小的文件进行了优化。

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.

虽然协议支持服务器到客户端范围请求,但它不允许反向操作。即使两端的软件不受卷的影响,您推送的数据越多,可能会丢失连接的时间间隔越大。但最大的问题是最后一句中的警告。