On Sun, 28 Jul 2002 00:51:06 -0700 (PDT), [EMAIL PROTECTED] (Nate)
wrote:
>i'm writing a website that requires an upload for pictures. I have figured out how to
>get the image, upload it to the correct dirctory and save successfully, but the
>problem comes with the fact that i have to specify the filename. i want to know how
>to grab the filename from the input of the following script (and by the way, i do not
>take credit for this script. i've only been programming in perl for about a day)
It's best to use CGI.pm for uploads, it will handle the
filename for you. In your upload form, set the param file.
See the sample html upload form at the end.
#upload.cgi
#######################################################
#!/usr/bin/perl -T
use strict;
use warnings;
use CGI;
$CGI::DISABLE_UPLOADS = 0;
my $query = new CGI;
my $upload_dir = "uploads"; #permissions for dir are set
my $file = $query->param("file");
my $filename = $file;
$filename =~s/.*[\/\\](.*)/$1/; #some taint checking
open (UPLOADFILE, ">$upload_dir/$filename");
while ( <$file> ){
print UPLOADFILE $_;
}
close UPLOADFILE;
print $query->header();
print <<END_HTML;
<HTML>
<HEAD> <TITLE>Thanks!</TITLE> </HEAD>
<BODY bgcolor="#ffffff"><br>
<P>Thanks for uploading file : $filename!</P>
</BODY>
</HTML>
END_HTML
############################################################
#upload.html
#########################################################
<html>
<form enctype="multipart/form-data" method=post
action=http://zentara.zentara.net/~zentara/cgi-bin/upload.cgi>
<input type=file name=file >
<INPUT TYPE="submit" VALUE="Send!">
</form>
</html>
###########################################################
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]