Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: CGI file upload - endless loop??

by sedhed (Scribe)
on Jul 18, 2002 at 01:26 UTC ( #182674=note: print w/replies, xml ) Need Help??

in reply to CGI file upload - endless loop??

It may very well be just a timeout problem like joealba said, but your perl code could be the problem. (Your HTML form looks fine.) To elaborate:

When you submit a multipart form, your browser packages up the file you specified in the file field and sends it along in the HTTP request to the server. So the initial request is when the actual transfer takes place, which can make it appear that it's hung, when it's really just still sending. reads in the file, and places it in a temp file. Only then is your program really able to spit headers and content back to the browser. So if it's a big file and you're on a modem, it will appear to hang, and may even time out.

(You don't have to process the file, it will just be deleted if you don't.) Try a simple CGI response like:

#!/usr/bin/perl -w use strict; use CGI; my $q = new CGI; print $q->header(); if ($q->param()) { print $q->ul( 'Got Something:', $q->li( [map {"$_: ".$q->param($_)} $q->param()] ) ); } else { print 'Got squat, sorry'; }

Anyway, go ahead and post your code, someone will be able to spot the breaking point if there is one.

PS, I have noticed that in particular IE 5.5 on MacOS seems to have trouble sometimes with all of my upload scripts. If that's your OS, you might try debugging from another machine to be sure it's not a client-specific problem.

Replies are listed 'Best First'.
Re: Re: CGI file upload - endless loop??
by lpoht (Sexton) on Jul 19, 2002 at 19:17 UTC
    First, thanks for your response sedhed. I tried your script and using the form I posted earlier on this thread, came up with some confusing results. Note that I added a text field on the form to make sure that it was sending something in the post. When I uploaded a small text file, the CGI responded with "Got squat" (even though the text field had text in it). When I uploaded a larger (90kb) image file, Netscape responded (client side)"A network error occurred while Netscape was sending data. (Network error: Connection Aborted). Try Connecting again." IE responded with "Cannot find server or DNS error". I added the line $cgi_lib::maxdata = 2000000; to make sure that size limitations wern't the problem. This code did not fix the problem. I can upload a 70kb file (getting "got squat" as the answer), but not a 90kb (or larger) file. The script is running on a PII 400Mhz server, which is on the same LAN as my machine, so bandwidth is not an issue (100BaseT ethernet). Any ideas? Thanks for your help.

      Well first things first... The syntax for setting upload limits is:

      $CGI::POST_MAX=1024 * 200; # max 200k posts # also, though it's already a default... $CGI::DISABLE_UPLOADS = 0;

      I don't know where your got the $cgi_lib::maxdata line, but it's not going to to anything. Note that is entirely different from, and is the generally recommended tool. Sounds like you might be looking at docs or code that were written for

      To narrow the problem, you could try a simple form with no file fields, just a text box or two, and see how the simple test script responds.

      I've posted a copy of the test script at, feel free to point your form at it for testing. (Max 200k posts is set.)

      Update, typo: changed from /cgi/ to /cgi-bin/

      If the test script works on my server, but not yours, I suspect you might have networking and/or server problems. On the other hand, if it doesn't work for you on my server, I suspect you have client/browser problems, since your sample form works nicely for me when pointed at the above URL. I get...

        Got Something:
      • file: C:\temp\test.jpg
      • Submit: Add Image

      What OSes are involved, and what web server software are you using? Also, be sure to clear your browser cache when doing testing like this, I tell ya the wierdest stuff can happen with IE's caching :)

      Good luck....

        Thanks, the problem was that Perl had defaulted to disabe uploads. Adding $CGI::DISABLE_UPLOADS = 0; worked. Thanks again!!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://182674]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2021-01-28 02:43 GMT
Find Nodes?
    Voting Booth?