• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 480
  • Last Modified:

HTML File Upload sent to PHP handling page times out?

I'm trying to understand how these HTML INPUT file uploads work.  At what point does the PHP page take over the file, once it is fully loaded into the POST data?

My uploads are timing out when I try to upload like 150 megabytes and after about 30 minutes, but why should that have anything to do with the PHP max_input_time setting.  Isn't all the processing time happening on the HTML form while the file is sent to the server and then PHP handles the file?

Isn't the only interaction between the HTML form and the server.  And then later PHP gets involved once the file is fully uploaded.  I'm just trying to understand how this works because couldn't I set the action of the form to a blank page and it will not make a difference, it will still take a bunch of time to upload the file and not have anything to do with PHP?
0
parlays
Asked:
parlays
  • 3
  • 3
  • 2
  • +1
4 Solutions
 
siliconbritCommented:

It depends on how you are uploading...

Can you post the HTML form code that handles the upload?

0
 
parlaysAuthor Commented:
I use two methods one that sends it to be handled by FTP:
<form enctype="multipart/form-data" action="<?php // echo $_SERVER['PHP_SELF'];?>" method="POST">
            Please choose a file: <input name="txt_file" type="file" id="txt_file" tabindex="1" size="35"  />
            <input name="txt_fileName" type="hidden" id="txt_fileName" tabindex="99" size="1" />
            <input type="submit" name="SubmitFile" value="Upload File" accesskey="ENTER" tabindex="2" />
      </form>
The other form type I use is handled by PHP move_uploaded_file function:
 <form action="upload-process.php5" method="post" enctype="multipart/form-data" id="signup" name="signup" onsubmit="return checkExt(this);">
<input type="hidden" name="MAX_FILE_SIZE" value="700000000" />
<table>
<tr>
    <td colspan="1"  class="labelcell">File 1:</td>
    <td colspan="1" class="fieldcell"><input type="file" name="f1" /></td>
</tr>
<tr>
<td> <input type="submit" class="button" name="button1" id="button1" value="Upload File" /></td></tr>
</table>
</form>
0
 
steelseth12Commented:
>>I'm trying to understand how these HTML INPUT file uploads work.  At what point does the PHP page take over the file, once it is fully loaded into the POST data?

File uploads are loaded into the $_FILES array not POST.
As soon as the submit is pressed information is send to the action page.
php starts waiting for data to handle at that moment, All the data must be received before php can start processing.

>>My uploads are timing out when I try to upload like 150 megabytes and after about 30 minutes, but why should that have anything to do with the PHP max_input_time setting.  Isn't all the processing time happening on the HTML form while the file is sent to the server and then PHP handles the file?

max_input_time  determines how much time PHP will wait to receive file data.

>>
Isn't the only interaction between the HTML form and the server.  And then later PHP gets involved once the file is fully uploaded.  I'm just trying to understand how this works because couldn't I set the action of the form to a blank page and it will not make a difference, it will still take a bunch of time to upload the file and not have anything to do with PHP?

If you set the action to a .html page it will take a long time to upload because you still have to transfer the data from your computer to the server, but max_input_time will play not difference because the php parse is not involved. If you set the action to a .php even a blank one max_input_time gets into effect.

How much time it takes for the file to upload only depends on your upload speed and the servers download speed.

It doesnt matter if you move the file with the ftp functions or with move_uploaded_file or copy or anything else. These will only start when the file is fully uploaded to the server.

If you have a 1mbit/sec upload speed the you would need a minimum of 13.3 minutes to upload a 100mbyte file
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
siliconbritCommented:
Agreeing with Stellseth, this is how I would describe the processing:

The form is configured with a PHP action, and this is all your browser knows about.

As soon as you press submit, the browser sends a request to the webserver for that PHP script, and includes a reference to the _FILES array.

The web server receives the request, starts the PHP script, which then requests the _FILES array from the web server process.  The webserver process does not deliver the array until it has completed downloading the _FILES array.

So, at this point, the PHP is waiting for its request to be completed by the web server.

It is *this* request from PHP to the web server which is timing out.  Only the PHP script can reply to the browser, so this is why you are seeing this error.

To be honest, 150MB is a big file to upload using a simple mechanism, and the timeout problem is a difficult one to solve.  There are lots of reasons for the problem, not least of which are your own upload speed (likely to be 512 or 256 at best), and server policies set by the server owner or the hosting company.

There are lots of free PHP scripts/classes on the web that manage this process more efficiently, and are more configurable and robust.  You might be well advised to start with one of those, since most of the work will already have been done.
0
 
nplibCommented:
if your page is timing out its probably due to php max execution time on the script.
add this line to the top of the PHP page that is receiving the file

set_time_limit(10000); which is 10000 seconds, just over 2 hours.

0
 
siliconbritCommented:

Just a note on max execution time.

If you are not the server owner you should check that this is acceptable.  Many hosts post strict limits on the execution time of scripts since they consume the 'shared' resources of the server.  If you have ever run a website on a shared hosting server, and wondered why sometimes the site seems slow, this is the reason.

You may find that setting this variable has no effect on the execution time limit set by the server owner for the same reason.

It's best to check.
0
 
parlaysAuthor Commented:
So many great points and I only have 500 points to award.  I wish I had 5000 points because you guys deserve it!!  Above and beyond the call of duty fellas, much appreciated, I hope you had a Happy Thanksgiving.

Thanks so much.... I'm curious where I can read more about how PHP handles the file upload as soon as submit is pressed, is it written about in the RFC documenation of HTTP or is it in the PHP manual?  Been looking for a good source to read to understand things like you masters do :)  thanks again.
0
 
parlaysAuthor Commented:
It is an honor to learn from true masters like yourselves... thank you gentlemen, you all deserve at least 500 or even 50,000 points but I had to split it up as evenly as I could. Thanks!!
0
 
nplibCommented:
You can look here,
although very technical
http://ca.php.net/features.file-upload
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now