我想使用 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
最佳答案
我还会检查最大输入时间和脚本执行时间。它们目前都设置为 300 秒(5 分钟)。这意味着用户必须在 300 秒内上传 150 MB(1200 兆位)。这意味着最终用户需要稳定且一致的 4mbps 连接 (1200/300 = 4) 才能在规定的时间内上传该文件。
我会推荐类似于这些设置的东西:
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
关于php - 使用php、apache上传大文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1700207/