Uploading Files From a CGI Script
#!/usr/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser); # Makes die work acceptably! Very important!!
print header(), start_html("File Uploading");
if (param("Upload File"))
{
$file = param("upload");
$basename = (split m|/|,$file)[-1];
open(F, ">./$basename") or die "Cannot load $basename!\n";
binmode $file;
binmode F;
while (<$file>)
{
print p($_);
tr/\r//d; # In case file is coming from Windows.
print F;
}
}
print start_multipart_form(),
filefield(-name => "upload",
-size => 75), br,
submit(-name => "Upload File"),
end_form,
end_html;