Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

File Uploading

by etzel42 (Initiate)
on Oct 15, 2003 at 22:02 UTC ( [id://299566]=perlquestion: print w/replies, xml ) Need Help??

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

I am having trouble with uploading (.mp3) files that are about 3MB in size or bigger. The below code works great until I try to upload a large file. Any thoughts?
use CGI; sub doUpload { my ($buffer); $query = new CGI; $filename = $query->param("file"); $filename =~ s/.*[\/\\](.*)/$1/; $myupload = $query->upload("file"); if ($filename =~ /.mp3/) { open (UPLOADFILE, ">$dirpath/$filename"); while (read($myupload, $buffer, 1024)) { print UPLOADFILE $buffer; } close (UPLOADFILE); } print "Location: $cgipath?action=success\nURI: $cgipath?action=success +\n\n"; }
I have also tried it this way:
if ($filename =~ /.mp3/) { open (UPLOADFILE, ">$dirpath/$filename"); while ( <$myupload> ) { print UPLOADFILE; } close (UPLOADFILE); }
Thanks.
-----------------------
I thought I got it working, but I didn't. It's not creating a file at all. I added this to it:
$CGI::POST_MAX = 102400;
or 100MB. How do I check the return value of "OPEN"?

Replies are listed 'Best First'.
Re: File Uploading
by mandog (Curate) on Oct 15, 2003 at 22:23 UTC

    You might add some more error checking for example: use strict;

    and...

    open (UPLOADFILE, ">$dirpath/$filename") or die "bad open $dirpath/$filename\n $!";

    You might look at CGI::POST_MAX Your system admin may have set it in CGI.pm

    perldoc CGI # skip some stuff $CGI::POST_MAX If set to a non-negative integer, this variable puts a ceiling on the size of POSTings, in bytes. If CGI.pm detects a POST that is greater than the ceiling, it will immediately exit with an error message. This value will affect both ordinary POSTs and multipart POSTs, meaning that it limits the maximum size of file uploads as well. You should set this to a reasonably high value, such as 1 megabyte.
Re: File Uploading
by vek (Prior) on Oct 16, 2003 at 17:04 UTC

    You should always check the return val of open to make sure you have created the file. Are you sure the file is being created? Are you left with a zero byte size file or no file at all? If you have no file at all then you had a problem creating the file. If you have a zero byte size file then that would sugget CGI::POST_MAX issues.

    -- vek --

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://299566]
Approved by mandog
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-23 16:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found