使用php、apache上传大文件 [英] upload large files using php, apache

查看:41
本文介绍了使用php、apache上传大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 PHP 和 Apache 服务器上传大约 150 MB 的文件.使用我的代码,我最多可以上传 5MB

I want to upload files of around 150 MB using PHP and Apache server. With my code i can upload upto 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) 才能在指定时间内上传该文件.

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.

我会推荐类似于这些设置的内容:

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

这篇关于使用php、apache上传大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆