WEB PAGE:
PERL SCRIPT:<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>
Items of note:#!/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; }
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.
In reply to Re: Picture upload script!
by TedPride
in thread File upload script printing to closed filehandle
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |