OnionKnight has asked for the wisdom of the Perl Monks concerning the following question:
I didn't include any of the HTML-dumping prints because those are unnecessary.use strict; use CGI qw(:standard); use Fcntl qw(:DEFAULT :flock :seek); use CGI::Carp qw(fatalsToBrowser warningsToBrowser); sub filesize { my $size = $_[0]; my $i = 0; my @suf = ("B", "KiB", "MiB", "GiB", "TiB"); for (; $size >= 1024; $i++) { $size /= 1024; } return sprintf("%.1f %s", $size, $suf[$i]); } my ($password, $file) = (param("password"), param("file")); if ($ENV{"REQUEST_METHOD"} eq "POST" && defined $file && defined $pass +word) { use constant UPLOADPUB => "C:\\Program Files\\Apache Group\\Apache +2\\htdocs\\upload\\"; use constant UPLOADDIR => "C:\\Documents and Settings\\Onion Knigh +t\\Desktop\\"; use constant MAXSIZE => 1048576; seek($file, 0, SEEK_END); my $size = tell($file); seek($file, 0, SEEK_SET); if ($password eq "") { if (sysopen(FILE, UPLOADDIR.$file, O_WRONLY | O_CREAT | O_TRUN +C)) { flock(FILE, LOCK_EX); binmode FILE; my $buffer; while (read($file, $buffer, 512)) { print FILE $buffer; } print " $file uploaded successfully! (" +, &filesize($size), ")"; close(FILE); } else { print " Couldn't write file to disk."; } } elsif ($password eq "guest") { if ($size < MAXSIZE) { if ($file !~ /^\./) { unless (-e UPLOADPUB.$file) { if (sysopen(FILE, UPLOADPUB.$file, O_WRONLY | O_CR +EAT | O_TRUNC)) { flock(FILE, LOCK_EX); binmode FILE; my $buffer; while (read($file, $buffer, 512)) { print FILE $buffer; } print " $file uploaded succ +essfully! (", &filesize($size), ")"; close(FILE); } else { print " Couldn't write file + to disk."; } } else { print " File exists already."; } } else { print " Filename not allowed."; } } else { print " Filesize too big!"; } } else { print " Password incorrect."; } } else { print " <br />"; }
Edited by Arunbear: Changed title from 'mod_perl mod_perl lol', as per Monastery guidelines
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trying to make a simple file uploader CGI script
by Joost (Canon) on Aug 04, 2005 at 23:27 UTC | |
|
Re: Trying to make a simple file uploader CGI script
by bart (Canon) on Aug 05, 2005 at 08:21 UTC | |
|
Re: Trying to make a simple file uploader CGI script
by wink (Scribe) on Aug 05, 2005 at 08:23 UTC |