Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
PHP uploading large files, takes long and error

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?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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.

about 4 years ago · Santiago Trujillo Report

0

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

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!