This is a tutorial on how to upload a file using perl CGI.
#!/usr/bin/perl -w
use strict;
use CGI;
use CGI::Carp qw ( fatalsToBrowser );
use File::Basename;
$CGI::POST_MAX = 1024 * 5000;
my $upload_directory = "/var/www/upload/";
my $cgi = new CGI;
my $filename = $cgi->param("temp_file");
if ( $filename ) {
my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' );
$filename = $name . $extension;
my $filehandle = $cgi->upload("temp_file");
open ( my $OUTFILE, ">$upload_directory/$filename" ) or die "$!";
binmode $OUTFILE;
while( <$filehandle> ) {
print $OUTFILE;
}
close $OUTFILE;
print $cgi->header ( );
print <<END_HTML;
<html>
<body>
<p>Upload successful!</p>
</body>
</html>
END_HTML
} else {
print $cgi->header ( );
print <<END_HTML;
<html>
<body>
<form action="/mod-cgi/upload.cgi" method="post" enctype="multipart/form-data">
<input type="file" name="temp_file" />
<input type="submit" />
</form>
</body>
</html>
END_HTML
}