?
Solved

HTML File Upload sent to PHP handling page times out?

Posted on 2007-11-22
9
Medium Priority
?
451 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 800 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 11

Accepted Solution

by:
siliconbrit earned 1000 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
 
LVL 17

Assisted Solution

by:nplib
nplib earned 200 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 1000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

777 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