Hi all,
I've not used C::A to upload files. Anything different or do I just use
standard CGI? If different, does anyone have some basic code they can share.
I'm just allowing uses to upload a small .gif or .jpg which will be stored
in the database or in a folder. I have a validation sub that untaints and
checks file type.
Here's how I used to do it:
sub upload_file {
$| = 1;
my ($upload, $max, $upload_dir, $filename) = @_;
$filename =~ s/ /_/g;
$filename =~ s/^.*[\/ | \\](.*)$/$1/; #strip off path
my $upload_filehandle = $query->upload($upload);
my $size = $ENV{CONTENT_LENGTH};
if ($size > $max) {
return ($filename,"File is too large to upload.",$size);
} #the returns are to an error "handler"
if (-e "$upload_dir/$filename") {
unlink "$upload_dir/$filename";
}
open UPLOADFILE, ">$upload_dir/$filename" or return($filename,$!,$size);
binmode UPLOADFILE or return($filename,$!,$size);;
while ( <$upload_filehandle> ) {
print UPLOADFILE or return($filename,$!,$size);
}
close UPLOADFILE or return($filename,$!,$size);;
return ($filename, "", $size);
}
Thanks all!
Brad
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]