开发者

upload large files using php, apache

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);
}开发者_如何学Python
    # 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


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


If you are using a shared server and 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.

 upload_max_filesize = 150M
 post_max_size = 150M
 memory_limit = 512M
 max_execution_time = 1200 


here is some good info about uploading files in PHP

Upload files PHP info

Or you could also read up on it here using an Java applet that uploads the file in chunks. Search for Jupload

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.


Chunking file uploads using ajax

I tested many solutions and my choice is Blueimp. Here is my rating list:

  1. Blueimp - 111KB, https://github.com/blueimp/jQuery-File-Upload
  2. Plupload - 359KB, developed for TinyMCE, supports HTML5 to Flash, Gears, Silverlight and iFrame, http://www.plupload.com/
  3. Fineuploader - 944KB, http://fineuploader.com/

Other solution tested by me

  1. Uploadify - http://www.uploadify.com/
  2. Resumable - https://github.com/23/resumable.js
  3. Dropzonejs - http://www.dropzonejs.com/
  4. MooUpload
  5. Fancyupload
  6. Hayageek http://hayageek.com/docs/jquery-upload-file.php


You might try using AJAX and PHP streams, this way memory usage will be under 1MB no mater how big your file is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜