Good places for tutorials on file upload with CGI.pm 
Author Message
 Good places for tutorials on file upload with CGI.pm
Hi folks:
        I realize that this could be more a question for the
cgi-authoring group, but I just had a weird experience with the CGI.pm
module.  Here's the story:

Wrote a small test script to upload a file and print the contents to
screen.  When I first uploaded, chmoded, and ran the script, it gave
me the upload form.  I filled in the file-to-upload field, pressed the
'submit' button, and saw a binary string printed to the resulting
HTML.  Huh?  So, I went back, read the manpage for CGI, tried some
tweaks, uploaded again... and now its the damned 500 error!
Furthermore, no matter what changes I make, it always gives me the 500
(even when I reverted back to the displaying/not-working code).
Summary: what is up with the file upload thing?  I've been writing CGI
w/ CGI.pm for over 3 years, and this is the 1st time I've ever been
stumped by it.  Help from any angle would be great.  Thanks!

Dave Joyce

--------------------
Dave Joyce

http://www.*-*-*.com/



Sat, 17 Apr 2004 20:03:13 GMT  
 Good places for tutorials on file upload with CGI.pm

Quote:

> Wrote a small test script to upload a file and print the contents to
> screen.  When I first uploaded, chmoded, and ran the script, it gave
> me the upload form.  I filled in the file-to-upload field, pressed the
> 'submit' button, and saw a binary string printed to the resulting
> HTML.  Huh?  So, I went back, read the manpage for CGI, tried some

Hard to guess without seeing the code, but if your script was written
to "print the contents to screen", no wonder you saw it.

Quote:
> tweaks, uploaded again... and now its the damned 500 error!
> Furthermore, no matter what changes I make, it always gives me the 500
> (even when I reverted back to the displaying/not-working code).
> Summary: what is up with the file upload thing?  I've been writing CGI
> w/ CGI.pm for over 3 years, and this is the 1st time I've ever been
> stumped by it.  Help from any angle would be great.  Thanks!

No help without knowing the messages that your server sends to your
error_log. Obviously you broke your script while doing the tweaks.

I don't think your problems are file upload related.

Yours,

--
------------------------------------------------------------------------

 .project: Perl, mod_perl, DBI, Oracle, auth. WWW servers, XML/XSL, ...
Petition for a Software Patent Free Europe http://petition.eurolinux.org
------------------------------------------------------------------------



Sat, 17 Apr 2004 22:13:25 GMT  
 Good places for tutorials on file upload with CGI.pm

Quote:
>    I realize that this could be more a question for the
>cgi-authoring group, but I just had a weird experience with the CGI.pm
>module.  Here's the story:

[snipped description of unexpected behavior with CGI.pm file uploads]

I'll let list-socialization enforcers decide whether another list is
more appropriate, but my suggestion is that you post some code for
folks to look at.

I've built several systems with text and binary uploads, all using
CGI.pm; it just works for me now, and my initial learning curve has
faded from memory, but here are a few general questions and comments:

- What versions of Perl and CGI.pm are you working with? Some ISPs
still have versions of both that don't do so well with file uploads.
A few years ago I had troubles with uploads *from* Windows machines,
and other troubles uploading *to* Mac servers.

- Which CGI.pm documentation were you referring to? I bought Lincoln
Stein's book (The Official Guide to Programming with CGI.pm, Wiley &
Sons, 1998), and got file uploads to work with no other advice. When
I later found some problems, I went to Stein's comprehensive online
resource, at <http://www.wiley.com/legacy/compbooks/stein/>, and got
the answers I needed -- and the reassurance that the OS variations
weren't my fault or imagination. The module has obviously been
enhanced since the book was published, but the online site is quite
current. Lincoln now has his own site with *really* up-to-date stuff,
at <http://stein.cshl.org/WWW/software/CGI/>.

- As a test, simplify your upload script as much as possible, and
don't rely on it to present the uploaded image. Just see if your
script can get the image to land on the server, copy it to the right
place, assign an untainted name, and return its URL as confirmation.
Then point your browser directly at the image's URL and see if it's
there.

- In your simplified script, include some other bit of info to be
submitted in a text field, and try the script with just that, no file
upload, to be sure there isn't some other problem with the script, as
Honza Pazdziora just suggested.

- In your production script, pay attention to what Lincoln has done
for security with file uploads. Don't use the submitter's filename --
have your script generate a name. Consider limiting the acceptable
file length. Check MIME type.

-  When you copy the file from its initial location in a temporary
directory, use read() rather than < >.

- Do you use CGI::Carp in your scripts? Just add the line
     use CGI::Carp qw(fatalsToBrowser);
near the start of your script, and you'll get better error tracing
without even digging into your server's error logs. Or have it write
to a special test log with 'carpout'.

That's enough general stuff, without a more specific look at your
code and error messages.

HTH

1;

   - Bruce

__bruce_van_allen__santa_cruz_ca__



Sat, 17 Apr 2004 23:48:46 GMT  
 Good places for tutorials on file upload with CGI.pm

Quote:

> I just had a weird experience with the CGI.pm module. ...

Which browser are you trying this on?

File upload is a non-standard feature, and requires special
support from the browser.

The only browser I'm 95% confident supports it is Netscape 4,
and I'm 95% sure older versions of IE *don't* support it.

--
John Porter

Somebody set up us the bomb!!!



Sun, 18 Apr 2004 00:31:32 GMT  
 Good places for tutorials on file upload with CGI.pm
Tutorial # 37: http://savage.net.au/Perl-tutorials.html

--
Cheers
Ron Savage

http://savage.net.au/index.html



Sun, 18 Apr 2004 16:27:03 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. turbo pascal 7.0 command line params

2. Message from Media Architects on ImageKnife VBX (from BVSP)

3. CGI.pm Bug: file upload file size mismatch when file size is close to buffer size

4. CGI.pm and file-upload.cgi

5. Problems with http file upload using cgi.pm and cgi-lib.pl

6. CGI.pm TEMP files not deleted on NT after file upload

7. DBI.pm CGI.pm tutorial needed

8. CGI.pm file upload problem

9. Apache mod_perl problem w/ CGI.pm file upload

10. File Uploads using CGI.PM

11. File Upload Problem w/ CGI.pm

12. CGI.pm - out of memory with file upload?

 

 
Powered by phpBB® Forum Software