CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2002
    Location
    Right here.
    Posts
    150

    Tricky Uploading

    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>

  2. #2
    Join Date
    Jul 2002
    Location
    Don't Know, Don't Care
    Posts
    346
    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.

    C G C F A D--Feel the Noise

    "When your life goes nowhere and leads back to me, doesn't that tell you something?"
    ~Gray Area Fury

  3. #3
    Join Date
    Aug 2002
    Location
    Reykjavik, Iceland
    Posts
    201
    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' />

  4. #4
    Join Date
    Aug 2002
    Location
    Washington, USA
    Posts
    104
    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, a java-applet ftp client that you can embed in the web page.
    - Shawn
    MCP, VB6: Desktop Apps
    [ C# | VB | .NET | Java | VC++ | Perl | PHP | Javascript ]
    Unless otherwise stated, all sample code provided is UNTESTED.
    http://www.codemastershawn.com

  5. #5
    Join Date
    Jan 2002
    Location
    Right here.
    Posts
    150
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured