php 使用php、apache上传大文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1700207/
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
upload large files using php, apache
提问by Ank
I want to upload files of around 150 MB using PHP and Apache server. With my code i can upload upto 5MB
我想使用 PHP 和 Apache 服务器上传大约 150 MB 的文件。使用我的代码,我最多可以上传 5MB
<?php
$path = $_COOKIE['Mypath'];
$target_path = "uploads/".$path ;
if(!isDir($target_path))
{
mkdir($target_path);
}
# Do uploading here
$target_path = "uploads/".$path ."/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
header("Location: somepage.html");
}
else
{
echo "File not uploaded";
}
?>
php.ini
配置文件
max_execution_time = 300 ; Maximum execution time of each script, in seconds
max_input_time = 300 ; Maximum amount of time each script may spend parsing request data
;max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 128M ; Maximum amount of memory a script may consume (128MB)
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
;upload_tmp_dir =
; Maximum allowed size for uploaded files.
upload_max_filesize = 200M
回答by Kurt Payne
I'd also check the max input time and script execution time. They're both currently set to 300 seconds (5 minutes). That would mean the user has to upload 150 mb (1200 mega-bits) in 300 seconds. That means the end user would need a solid and consistent 4mbps connection (1200 / 300 = 4) to upload that file in the allotted time.
我还会检查最大输入时间和脚本执行时间。它们当前都设置为 300 秒(5 分钟)。这意味着用户必须在 300 秒内上传 150 mb(1200 兆位)。这意味着最终用户需要稳定且一致的 4mbps 连接 (1200 / 300 = 4) 才能在指定时间内上传该文件。
I would recommend something similar to these settings:
我会推荐类似于这些设置的东西:
file_uploads = On
upload_tmp_dir = "/your/tmp/dir"
upload_max_filesize = 150M ; You may want to bump this to 151M if you have problems with 150 mb files
max_execution_time = 1200 ; 20 minutes, which is a 150 mb file at 1mbps
max_input_time = 1200
回答by Harshad M
If you are using a shared serverand want to upload large files, create a php.ini file and write the following code into it and put it in the folder where you are uploading the files, i.e. the destination of your uploaded files.
如果您使用的是共享服务器并且要上传大文件,请创建一个 php.ini 文件并将以下代码写入其中并将其放在您上传文件的文件夹中,即您上传文件的目的地。
upload_max_filesize = 150M
post_max_size = 150M
memory_limit = 512M
max_execution_time = 1200
回答by Vlad Alivanov
Chunking file uploads using ajax
使用ajax分块文件上传
I tested many solutions and my choice is Blueimp. Here is my rating list:
我测试了很多解决方案,我的选择是 Blueimp。这是我的评分清单:
- Blueimp - 111KB, https://github.com/blueimp/jQuery-File-Upload
- Plupload - 359KB, developed for TinyMCE, supports HTML5 to Flash, Gears, Silverlight and iFrame, http://www.plupload.com/
- Fineuploader - 944KB, http://fineuploader.com/
- Blueimp - 111KB,https://github.com/blueimp/jQuery-File-Upload
- Plupload - 359KB,为 TinyMCE 开发,支持 HTML5 到 Flash、Gears、Silverlight 和 iFrame,http://www.plupload.com/
- Fineuploader - 944KB,http://fineuploader.com/
Other solution tested by me
我测试的其他解决方案
- Uploadify - http://www.uploadify.com/
- Resumable - https://github.com/23/resumable.js
- Dropzonejs - http://www.dropzonejs.com/
- MooUpload
- Fancyupload
- Hayageek http://hayageek.com/docs/jquery-upload-file.php
- 上传 - http://www.uploadify.com/
- 可恢复 - https://github.com/23/resumable.js
- Dropzonejs - http://www.dropzonejs.com/
- 上传
- 花式上传
- Hayageek http://hayageek.com/docs/jquery-upload-file.php
回答by Arto Uusikangas
here is some good info about uploading files in PHP
这里有一些关于用 PHP 上传文件的好信息
Or you could also read up on it here using an Java applet that uploads the file in chunks. Search for Jupload
或者,您也可以使用 Java 小程序在此处阅读它,该小程序将文件分块上传。搜索 Juupload
php/Apache Config You will need to change the value of both upload_max_filesize and post_max_size to the largest filesize you would like to allow. Then restart apache and everything should work.
php/Apache Config 您需要将 upload_max_filesize 和 post_max_size 的值更改为您希望允许的最大文件大小。然后重新启动apache,一切都应该正常工作。
回答by SlasherZ
You might try using AJAX and PHP streams, this way memory usage will be under 1MB no mater how big your file is.
您可以尝试使用 AJAX 和 PHP 流,这样无论您的文件有多大,内存使用量都将低于 1MB。

