in reply to File upload script printing to closed filehandle

The following is a bare bones upload script:

WEB PAGE:

<HTML> <TITLE>Upload File</TITLE> <BODY BGCOLOR="#FFFFFF"> <form method="post" action="/cgi-bin/upload.pl" enctype="multipart/for +m-data"> <input type="file" name="graphic" size="35"> <input type="submit" value=" Upload "> </form> </BODY> </HTML>
PERL SCRIPT:
#!/usr/local/bin/perl ############################################ $base = "/usr/home/web67378/www/htdocs"; $folder = "$base/upload"; use CGI; $query = new CGI; print "Content-Type: text/html\n\n"; if ($filename = $query->param('graphic')) { if ($filename =~ /^([\w-]+\.(jpg|gif|png))$/) { $file_handle = $filename; $filename = $1; open(OUT, ">$folder/$filename") || &error('The file could not be written to the server.'); while (read($file_handle,$buffer,1024)) { print OUT $buffer; } close($file_handle); close(OUT); } } else { &error('No file was selected for upload.'); } print "Successful."; sub error { print shift; exit; }
Items of note:
1) Edit $base and $folder as necessary.

2) if ($filename =~ /^([\w-]+\.(jpg|gif|png))$/) {
Edit this so it matches your desired file name pattern. The current pattern is for image files only.

3. Add proper header and footer HTML so the output doesn't look like crud.