Perhaps you should follow the advice of the manpage:
When the form is processed, you can retrieve the entered
filename by calling param():
$filename = $query->param('uploaded_file');
Different browsers will return slightly different things
for the name. Some browsers return the filename only.
Others return the full path to the file, using the path
conventions of the user's machine. Regardless, the name
returned is always the name of the file on the user's
machine, and is unrelated to the name of the temporary
file that CGI.pm creates during upload spooling (see
below).
The filename returned is also a file handle. You can read
the contents of the file using standard Perl file reading
calls:
# Read a text file and print it out
while (<$filename>) {
print;
}
# Copy a binary file to somewhere safe
open (OUTFILE,">>/usr/local/web/users/feedback");
while ($bytesread=read($filename,$buffer,1024)) {
print OUTFILE $buffer;
}
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;
}
In an array context, upload() will return an array of
filehandles. This makes it possible to create forms that
use the same name for multiple upload fields.
This is the recommended idiom.
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.