Wassercrats has asked for the wisdom of the Perl Monks concerning the following question:

I have a web host that doesn't have the CGI-LIB module (maybe for security reasons that I saw mentioned at http://www.rice.edu/perl4lib/archives/2000-03/msg00022.html ), and I'm trying to read an uploaded file submitted by a form. I can read non-uploaded data from the form using the CGI module, but for some reason, the following doesn't print out the uploaded data:

from form:
<html><body> <form enctype="multipart/form-data" action="path_to_script_that_reads_ +non_uploaded_ data_only_for_some_reason" method="post"> <p>Upload test<input type="file" size="45" name="UploadedFile"></p> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </form></body></html>
from script:
use CGI; $CGI::POST_MAX = 4000; $CGI::MULTIPART; ### Doesn't seem to be needed in script for reading f +orm data, but I put it here in desperation $fdata = CGI->new(); $Test_Field = $fdata->param('UploadedFile'); print"$Test_Field";exit;
Seems like it should at least print out the file name, but it doesn't. I might try to create the file upload part of the form from the script, but I already have a HTML form for the other fields, so I'd like stick with all HTML.

I read that LWP can be used for this. Must I figure out how to do that, or is there some way I can fix the above script and just use the plain old CGI module?

In another experiment, I used the script at http://www.speakeasy.org/~cgires/cgi-tour.html#summary which is a modified version of CGI_LIB, but it's old and didn't work on a plain text file at all, and garbled a cgi script that I tried uploading. I might try rewriting the parsing routine in that script, but it seems like a long, sloppy way to handle this, especially since it's only for one form field.

Any suggestions?

Replies are listed 'Best First'.
Re: Reading file uploads
by benn (Vicar) on Apr 24, 2003 at 23:13 UTC
    Your CGI code looks ok in principle, and is definitely the way to do it - as recently explained at length elsewhere, LWP is a module for retrieving pages, not from creating them and dealing with their submissions.

    This may be simply to do with exactly *where* you're running the script from and printing the result...if you're submitting from a browser, and want the script to print back to the browser, you'll need to stick a print $fdata->header() before that print statement, so that the browser will be able to display the result.
    Cheers,
    Ben

    A reply falls below the community's threshold of quality. You may see it by logging in.