On Fri, Oct 04, 2002 at 01:40:49 PM, Sean Quinlan wrote:
> In your CGI you will need to make a CGI object. Read the documentation,
> but commonly its:
> use CGI qw(:standard);
> our $CGI = new CGI;
>
> Then in the subroutine where you read the file:
> my $datafile = $CGI->param('datafile');
> while (<$datafile>) {
> # some stuff
> } # while
The docs on my system (2.75) suggest that for versions above
2.47, one should use the new upload() function, as using param()
alone may cause problems:
However, there are problems with the dual nature of the
upload fields. If you "use strict", then Perl will com-
plain when you try to use a string as a filehandle. You
can get around this by placing the file reading code in a
block containing the "no strict" pragma. More seriously,
it is possible for the remote user to type garbage into
the upload field, in which case what you get from param()
is not a filehandle at all, but a string.
To be safe, use the upload() function (new in version
2.47). When called with the name of an upload field,
upload() returns a filehandle, or undef if the parameter
is not a valid filehandle.
$fh = $query->upload('uploaded_file');
while (<$fh>) {
print;
}
(`perldoc CGI', search for 'CREATING A FILE UPLOAD FIELD')
> One other important consideration though is that the form presented to
> the user must be multipart. So your form tag in your web page should
> look something like:
> <FORM ACTION="http://$ENV{HTTP_HOST}/cgi-bin/foo.cgi"
> enctype="multipart/form-data" METHOD="post">
Right. And if you are using CGI.pm for HTML output, you can use
start_multipart_form() rather than start_form() to properly set the
encoding in the <FORM> tag.
-E
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm