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);
}
# 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
Solution 1:
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
Solution 2:
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