php - 使用php、apache上传大文件

标签 php apache file-upload

我想使用 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/

相关文章:

php - 按照给定列表中 ID 的顺序对数据进行排序

php - 结果从数据库中可用的确切行返回减去 1(负 1)的值

php - 将图像上传到服务器 PHP Android

java - Hadoop (1.1.2) XML 处理和重写文件

php - 在 puphpet PHP 5.6 上找不到类 'SimpleXMLElement'

php - UTF-8贯穿始终

Asp.Net 上传前检查文件大小

PHP : comparing fetched date with today

android - Multipart OkHttp3/Retrofit 2 某些设备上传速度有问题

javascript - 蒸发JS : Always get 403 SignatureDoesNotMatch error after resuming an upload