#!/usr/local/bin/perl -w # script name = upload_form.cgi use strict; use CGI; $query = new CGI; print $query->header; print $query->start_html; print $query->start_multipart_form(-action=>"image_writer.cgi"); #below print $query->filefield(-name=>'file'); print $query->submit(-value=>'Upload File'); print $query->end_form; print $query->end_html; exit; #### #!/usr/bin/local/perl -w # name image_writer.cgi use CGI; $query = new CGI; $file = $query->param('file'); open IMAGE, ">/tmp/image"; while ($bytesread = read($file,$buffer,1024) ) { #treat as binary $total += $bytesread; #add the bytesread to a total if ($bytesread > 2000000) { # no files larger than 2Meg, please close IMAGE; $badboy = $ENV{'REMOTE_ADDR'}; $time = scalar localtime; unlink ("/tmp/image"); #delete the file that's too large and log the offense (below) die "$time: $badboy tried to upload a file that was too large"; } print IMAGE $buffer; } exit;