I'm uploading a large file via ajax. The upload speed is fine but when the progress bar get's to 100%, there is a long wait and then i get this error
Failed to load resource: the server responded with a status of 504 (Gateway Time-out) - upload.php.
The file does appear in the destination folder but there isn't a server response.
This doesn't happen to smaller files. It seems to take long to move_uploaded_file from the Temp folder to the destination folder.
var xhr, hUploadSpeed;
function sendFile()
{
document.getElementById("serverresponse").innerHTML = "";//clear previous server response
var url = "http://www.example.com/wp-content/themes/theme1/file-upload/upload.php";
var formData = new FormData(document.getElementById("form1"));
xhr = new XMLHttpRequest();
xhr.upload.addEventListener('progress', uploadProgress, false);//EventListener for upload progress
xhr.addEventListener('abort', uploadAbort, false);//EventListener for abort
xhr.addEventListener('error', uploadError, false);//EventListener for error
xhr.addEventListener('load', uploadThrough, false);//EventListener for completed upload
xhr.open("POST", url, true);
//xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //no longer necessary here
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4 && xhr.status == 200)
{
document.getElementById("serverresponse").innerHTML = xhr.responseText;
}
}
xhr.send(formData); //Send to server
hUploadSpeed = setInterval(UploadSpeed, 1000); //per seconds
}
Upload.php
//You can access the uploaded files through $_FILES
if(isset($_FILES["file1"]))
$target_file = $_SERVER['DOCUMENT_ROOT']."/videos/".$_FILES["file1"]['name'];
move_uploaded_file($_FILES["file1"]["tmp_name"], $target_file);
echo "File uploaded successfully.";
This works perfectly with smaller files 50mb but when i get to files around 300mb. It takes so long?
I have a dedicated server with this php.ini
upload_max_filesize = 1200M
post_max_size = 1200M
max_input_vars = 1000
memory_limit = -1
max_file_uploads = 20
max_execution_time = 7200
max_input_time = 7200
max_input_vars = 1000
Why does it take so long? How do i solve?
There's also memory_limit in php.ini that can affect upload. php.ini is a server config file.
You have to increase the following values in your php.ini file:
php_value upload_max_filesize 10M
php_value post_max_size 10M
php_value max_input_time 300
php_value max_execution_time 300
and then restart the server.
I think that your problem can be this php bug : https://bugs.php.net/bug.php?id=73807 You php config is ok.
Fixed in 7 and 7.1 branch. Not In php 5.6 now. Maybe soon. If you can, upgrade your app to 7.1 (performances are also more than 2 times faster), if you can't just wait php > 5.6.30