Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

input type='file' 2

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I am running the following simple HTML form to call the Perl script at the bottom of this post.
The script runs fine but depending on the size of the file selected to download, there is a delay before the text displays.
If I substitute the <input type='file'> command with a <input='text'> command, there is no delay.

The delay is more obvious on a slow internet connection which many of my clients have.

Could anyone suggest why there is such a long delay.

HTML:
<!DOCTYPE html>
<html>
<head>
<title>Upload Test</title>
</head>
<body>
<h1>File Upload Test</h1>
<FORM METHOD="POST" ACTION="cgi-bin/test2.pl" ENCTYPE="multipart/form-data">
<INPUT TYPE="file" NAME="FILEID" VALUE="" SIZE=50 MAXLENGTH=80><BR>
<INPUT TYPE="hidden" NAME="call" VALUE="uploadimage">
<INPUT TYPE="submit" NAME="submit" VALUE="Upload File To Server"></FORM>
</body>
</html>

Perl:
#!/usr/bin/perl
use strict;
use warnings;
print "Content-Type: text/html\n\n";
print "Start Script<br>";
print "This simple script only displays this text and performs no other function.";



Keith
 
Do you have a URL that we can test against? Because " there is a delay before the text displays." is somewhat vague.

And what browsers have you tested with?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
The following links to a basic form.
[URL unfurl="true"]http://www.studiosoft.co.uk/uploadtest.htm[/url]
The form is submitted to a Perl script which does not process the upload but displays a text message.

If I submit the form without selecting an image, the script is called and text created by the script is displayed instantly.
If I select a file, there is a delay before the text generated by script is displayed.
The delay is proportional to the size of the selected file.

I have only tested it on various versions of IE.

Keith
 
Keith I tested your page and got the following
Use caution on this site
An unacceptable security risk is posed by this site.
McAfee Security Rating: Yellow


Powered By: SiteAdvisor Enterprise

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Not sure what that is about, it gets a clean bill of health from Google and Sucuri Site Checker.
Could it be complaining because there is a file upload script on there?

Keith
 
If I select a file, there is a delay before the text generated by script is displayed.
The delay is proportional to the size of the selected file.

That would suggest that the delay is caused by the upload of the file. There really is nothing you can do if that is the case. If its a larger file it will taker longer to upload than a smaller file.

Do you need the file to be uploaded?

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
The whole point of my question was that up until this point, the file has not been uploaded.
In the example above, a file name has been selected and then a script has been called, the upload has not taken place.

Keith
 
In the example above, a file name has been selected and then a script has been called, the upload has not taken place.
That is not the case, file uploading (or downloading for that matter) over HTTP is a 'push' process,the client tells the server that there is 'X' number of bytes following, so the script will only run when the end of the form data is reached, so the upload HAS to take place before the server side processing starts.

Downloading is a 'push' of 'X' number of bytes to the client.


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
The moment you submit the form, the upload will take place. At what other time would the file upload if not when the form is submitted?

Even if the file is not processed, it will have been uploaded to the server before your perl script runs.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Thanks both of you, that answers the question I have been asking for a while.
I always assumed that this code:-
Code:
while($bytesread=read($fileID,$buffer,1024)){
	print OPF "$buffer";
	$sum_bytes=$sum_bytes+1024;
}
was responsible for the upload but from what I have learnt here, this only takes it from memory on the server and copies it to a file.
What happens in this process when very large files are uploaded?
How is it possible to implement a progress bar if the file is uploaded before the server side processing begins?

Keith
 
Its usually not possible. Most progress bars are done using Ajax techniques, or even flash based uploaders to upload files. But a standard form submission upload will not have a progress bar. Because there is no server side control of the upload until its completed, and no client side file control after the file has been chosen. Its all up to the browser at that point.

This is a security precaution, so the files variable cannot be altered by client side code, and the upload remains what the user selected, instead of an arbitrary chosen file path by some malicious client side code.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top