Click to See Complete Forum and Search --> : Tricky Uploading


mjxnjx
October 14th, 2002, 03:57 PM
Hello Gurus!

The following upload script works fine for small file uploads. But if the upload takes too long (for bigger files, for example), the UploadWindow errors out "Page Cannot be Displayed" after a few moments. I'm assuming the window is waiting for a response back, not getting it, and is erroring out as a result.

Here's an overview of what's supposed to be happening:
1) User is given a form by which to select a file to upload.
2) User clicks on the submit button, thereby opening a new window that will handle the file upload.
3) The main window then updates with a new message and is free for use to do other things while the upload is happening.
4) When the upload is complete, the Uploadwindow closes automatically by the window.close() command sent by the server side script.

Here's what happens with a bigger file:
4) The Upload is interrupted part way through by a message "Page Cannot be Displayed". The Upload is also interrupted so the file is only partially transferred. The server never has the opportunity to send window.close() so the Uploadwindow is left open with this ugly message of "Page Cannot be Displayed".

The browser seems to be really impatient on getting a response during a bigger upload. How can I make it happy?

<HTML>
<HEAD>
<TITLE>Uploading Single File</TITLE>
<SCRIPT LANGUAGE='JavaScript'>
<!-- Begin
function checkFile()
{
tmp=document.form1.cmuds.value;
if (tmp.length<1)
{
alert('Please enter a file to upload before continuing')
document.form1.cmuds.focus();
}
else
{
upwin = window.open('','UploadWindow','dependant=yes,height=50,width=300,menubar=no,status=no,titlebar=no,toolbar=no,alwayslowered=yes');
upwin.document.writeln("<HTML><HEAD>");
var filepath;
re = / /gi;
filepath = tmp.replace(re,'%20');
upwin.document.writeln("</HEAD><BODY><CENTER>Uploading...",tmp,"</BODY></HTML>");
upwin.document.close();
document.form1.submit();
document.close();
document.write("<HTML><HEAD><TITLE>Uploading Single File</TITLE>");
document.write("</HEAD><BODY><p><center>");
document.write("File is Uploading in another window. This window is free for use while that one is uploading. </body></html>");
document.close();
}
}
// End -->
</script>
</HEAD>

<BODY>
<p><center>
<form target='UploadWindow' action='http://yadaplace/yadayada.pl' method='POST' focus='cmuds' name=form1 enctype='multipart/form-data'>
Please Select the File you wish to Upload to the Server.<BR><BR>
<input type='file' name='cmuds' size=50>
<input type=submit name='uploadit' value='Upload It' OnClick='checkFile()'>
</form>
</body>
</html>

Waldo2k2
October 15th, 2002, 08:25 PM
where's the code you use to upload the file? is it in the .pl file? you should post that, i htink the problem has to do with that (sending requests...etc.) I can read perl so i should be able to help.

websmith99
October 17th, 2002, 06:49 PM
Here's what I notice.

You are creating a race condition by calling the 'checkFile()' JavaScript function in an onclick event on a submit button!

Since checkFile() will be submitting the form anyway through document.form1.submit(), you should change the call to checkFile() to an onSubmit event in the <form> tag:



<form target='UploadWindow' action='http://yadaplace/yadayada.pl' method='POST' focus='cmuds' name=form1 enctype='multipart/form-data' onsubmit=''checkFile()'>


<input type=submit name='uploadit' value='Upload It' />

ShawnDev
October 18th, 2002, 08:47 PM
How big a file are we talking about here? I ran into this with a client once where they were expecting their customers to be able to upload 75-100mb files. We were using PHP and although we tried increasing the time-out settings for both the web server and PHP itself, we couldn't push them out far enough and still keep the server functional.

What we wound up doing was testing and then suggesting/recommending U-Upload (http://www.unlimitedftp.ca/uupload/index.jsp), a java-applet ftp client that you can embed in the web page.

mjxnjx
October 21st, 2002, 11:31 AM
Hello,


Thanx everyone for the help.

I first took Waldo's suggestion and scanned through the PHP script. I am no "PHP guru", but since it "Errors Out" at a random location each time and only for large files, I am inclined to believe it's ok. I had someone verify it for me, and they said it looks normal.

The "CheckFile" function used to be called using "return CheckFile()", and I only removed the involved validation in order to not confuse anyone on my post. I agree though, it could be called better if i'm not doing validation.

I think Shawn may have hit it on the nose. The uploads can be anywhere between 2mb to a high 300mb! I'll look into the U-Upload as an alternative.

Thanx All