I write web apps that usually require/allow the uploading of files (pdf, jpg, doc, cvs). I have lately been using the following (just a snippet for comparison reasons):
$filename = $sourcepath = $query->upload($file); $filename =~ /([\w. -]+)$/i; $filename = $1; $filename =~ s/ /_/g; my $size = $ENV{CONTENT_LENGTH}; if ($size > $max) { return ($filename,"File is too large to upload.",$size); } open(OUTPUT, ">$path/$filename") or return ($filename, "Cannot open '$ +filename'. Contact Webmaster"); ; binmode($filename); binmode(OUTPUT); while( read($sourcepath, $buffer, 64*2**10) ) { print OUTPUT $buffer; } close(OUTPUT);
However, I just saw this in a recent unrelated node.
my $upload_filehandle = $query->upload("filename"); open UPLOADFILE, ">$upload_dir/$filename"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;
What are the advantages and disadvantages of both? The last one sure looks cleaner--do I need all the stuff in the former? General comments? Thanks.
In reply to File uploading methods compared by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |