Solved

HTML File Upload sent to PHP handling page times out?

Posted on 2007-11-22
9
433 Views
Last Modified: 2010-04-21
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
Comment
Question by:parlays
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 11

Expert Comment

by:siliconbrit
ID: 20336835

It depends on how you are uploading...

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

0
 

Author Comment

by:parlays
ID: 20337426
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
 
LVL 20

Assisted Solution

by:steelseth12
steelseth12 earned 200 total points
ID: 20338454
>>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
 
LVL 11

Accepted Solution

by:
siliconbrit earned 250 total points
ID: 20338602
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 17

Assisted Solution

by:nplib
nplib earned 50 total points
ID: 20338882
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
 
LVL 11

Assisted Solution

by:siliconbrit
siliconbrit earned 250 total points
ID: 20339142

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
 

Author Comment

by:parlays
ID: 20340346
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
 

Author Closing Comment

by:parlays
ID: 31410609
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
 
LVL 17

Expert Comment

by:nplib
ID: 20340355
You can look here,
although very technical
http://ca.php.net/features.file-upload
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now