Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: need help with file uploading

by stephen (Priest)
on Jun 19, 2001 at 22:39 UTC ( #89769=note: print w/ replies, xml ) Need Help??

in reply to need help with file uploading

In this code:

sub doUpload { my ($bytes, $buffer, $bytesread); my $filehandle = CGI::param('filepath'); open OUTFILE, '>$filehandle' or die "Couldn't open output file: $!\n";
You're using single quotes when opening OUTFILE. Therefore, you're always writing to a file named '$filehandle'-- not the contents of the variable, but the string '$filehandle' itself. Change those to double quotes. Better yet, use File::Temp to create a temporary file if you're using 5.6.

Additionally, you should use upload() instead of param() to get the uploaded filehandle for security reasons. Namely, instead of saying:

my $filehandle = CGI::param('filepath');
my $filehandle = upload('filepath') or die "No file uploaded!";
Since upload() returns undef if there's no upload field with the given name, it'll error out if the user didn't upload a file. More secure, since the user can't try to mess you up by providing a text input to 'filepath'.

Note: Code untested, since I don't have a web server handy.


Comment on Re: need help with file uploading
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2015-12-01 01:54 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (791 votes), past polls