Hi everyone,

I'm trying to upload an mp4 file on my localhost. The page continuously loads until giving me a Request Timeout.

The file is 17Mb. I've tested an image file which is 95Kb and that uploads fine.

I've changed various settings in my php.ini which I can see have taken effect via php_info().

file_uploads: On
max_input_time: 300
max_execution_time: 300
post_max_size: 257M
upload_max_filesize: 256M

and for Apache

Timeouts: Connection: 3600 - Keep-Alive: 5

The page loading seems to be mainly associated with the Apache setting which was orignally 60 seconds and is now reaching the hour due to the new setting.

I'm sure the file shouldn't take this long to upload or am I wrong in that assumption?

What else do I need to tinker with to get the file to upload?

Recommended Answers

All 9 Replies

Apache can load a module to control the upload/download bandwith, this is not a default setting, so you should check with your hosting if there are any limits. You can also try to see the headers sent and received by the uploading session.

Also Apache can set the post max size which differs from PHP settings, check for LimitRequestBody:

This can be set in the .htaccess file to override hosting default settings.

Thanks cereal.

I've set LimitRequestBody to 0 in the httpd.conf for Apache though from what I understand it defaults to 0 anyway.

I'm using WAMPServer 2.5 with Apache 2.4.9.

I feel I've changed every setting that is commonly mentioned.

The error is displaying as "Request Timeout. Server timeout waiting for the HTTP request from the client."

Nothing is showing about it in the Apache error log or the PHP error log.

The page doesn't even seem to be loading to the point of running the php on the page.

I feel it's a server thing but I'm completely lost with how to fix it. The only mentions the server gets are with regards to the LimitRequestBody and Timeouts, both of which I've adjusted accordingly.

"Request Timeout. Server timeout waiting for the HTTP request from the client."

I'm not much confident with WAMP setups, but this seems to be error 408. I would test PHP configuration by running the internal server, so to understand if it depends on Apache, by the upload form or something else related to WAMP.

In order to test it, create a script with:

<?php

    vardump($_POST, $_FILES);

Then run:

php -S localhost:8000 c:\test.php

And finally use curl to send a request, for example:

curl --trace c:\curl_output.txt -X POST -F filename='asd.jpg' -F file=@c:\asd.jpg http://localhost:8000/

This should create an hex dump of the entire upload cycle, from here you can maybe understand why it hangs and see if through the internal server works.

You can, then, repeat the test by pointing the curl request to your upload script (and by adjusting the -F options to match your upload form), and see what happens to the script handled by WAMP.

A part this I cannot do much else, because we are exploring the issue without seeing the actual code, so if it does not help you may want to share the form and the receiver script.

Member Avatar for diafol

Sorry, but I may be missing the point. You say 'localhost' - are we to assume that this is your local copy of the site? Will you actually require your live remote site to replicate this functionality?

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        if(isset($_FILES["fileToUpload"])){
            $target_dir = "uploads/";
            $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
            $uploadOk = 1;
            $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
            // Check if image file is a actual image or fake image
            if(isset($_POST["submit"])) {
                $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
                if($check !== false) {
                    echo "File is an image - " . $check["mime"] . ".";
                    $uploadOk = 1;
                } else {
                    echo "File is not an image.";
                    $uploadOk = 0;
                }
            }
            // Check if file already exists
            if (file_exists($target_file)) {
                echo "Sorry, file already exists.";
                $uploadOk = 0;
            }
            // Check file size
            if ($_FILES["fileToUpload"]["size"] > 500000) {
                echo "Sorry, your file is too large.";
                $uploadOk = 0;
            }
            // Allow certain file formats
            if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
            && $imageFileType != "gif" ) {
                echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
                $uploadOk = 0;
            }
            // Check if $uploadOk is set to 0 by an error
            if ($uploadOk == 0) {
                echo "Sorry, your file was not uploaded.";
            // if everything is ok, try to upload file
            } else {
                if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
                    echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
                } else {
                    echo "Sorry, there was an error uploading your file.";
                }
            }
        }else{
            echo('$_FILES is empty');
        }
        ?> 
        <form method="post" enctype="multipart/form-data">
            <input type="file" name="fileToUpload" />
            <input type="submit" />
        </form>
    </body>
</html>

I tried some different files to upload. The mp4 file wasn't uploading. I changed the extension to mkv and it uploaded. Another mkv also uploaded. I tried the first mkv again this morning and it didn't upload. But the other did again.

I've downloaded sample mp4s and mkvs and they aren't working.

So I think I have my php settings and apache settings right but for some reason certain files in certain formats aren't uploading.

@diafol: Yes, this is all on my local system but once I have it working here I intend for it to go live.

@cereal:

array (size=1)
  'filename' => string ''20150822_134754.mkv'' (length=21)

array (size=1)
  'file' =>
    array (size=5)
      'name' => string '20150822_134754.mkv' (length=19)
      'type' => string 'application/octet-stream' (length=24)
      'tmp_name' => string 'C:\wamp\tmp\phpFC6E.tmp' (length=23)
      'error' => int 0
      'size' => int 17074844

From using curl.

It seems like it could be a browser issue. It works in chrome but not firefox.

Looking at the script, it shouldn't work at all with videos as it seems to be forged to allow only images. In addition, your script file size limit is 500000, i.e. 0.5MB:

if ($_FILES["fileToUpload"]["size"] > 500000) {

while the uploaded file is 17074844, i.e. 17.07MB.

The browser can be an issue because, sometimes, it can send a wrong mime-type and if you filter through that value then the script can fail. An example is the file you sent through curl, it returned:

'type' => string 'application/octet-stream' (length=24)

which is wrong for a matroska file, the correct type should be: video/x-matroska.

Since you want to allow videos instead of getimagesize() use the Finfo library, for example:

$f = (new Finfo(FILEINFO_MIME_TYPE))->file('asd.jpg');

But in order to work fine you need a magic file, which has some definitions used to match mime types of inspected files.

I'm not sure Microsoft Windows or WAMP provides such file, for more information check the comments in the documentation or just check within your system:

Diafol's question is pertinent: if your production server will be Linux there are chances that will behave differently from your actual environment. To be sure everything will work fine, you should try to create an environment very close to the production server or, if required, code to support multiple environments.

So, try to upload the file without the IF statements, simplify: read the $_FILES array, move the file to the store location then, if it works fine, add the conditions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.