bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File uploading methods compared
by mlh2003 (Scribe) on May 14, 2005 at 13:49 UTC | |
|
Re: File uploading methods compared
by eibwen (Friar) on May 14, 2005 at 14:01 UTC | |
by Animator (Hermit) on May 14, 2005 at 15:56 UTC | |
|
Re: File uploading methods compared
by zentara (Cardinal) on May 15, 2005 at 11:38 UTC | |
by Anonymous Monk on May 15, 2005 at 12:39 UTC |