ibjdt
Programmer
- Nov 25, 2002
- 63
i want to allow user to upload up to 4 images so i use the following code i found.
i modified it to loop through each image field name and process it if an image was uploaded.
the script performs properly except the files on my server are 0 bytes - the file isn't actually getting uploaded.
the file name is created on the server correctly and the correct file name is posted to the database. thanks for your suggestions.
i modified it to loop through each image field name and process it if an image was uploaded.
the script performs properly except the files on my server are 0 bytes - the file isn't actually getting uploaded.
the file name is created on the server correctly and the correct file name is posted to the database. thanks for your suggestions.
Code:
$upload_dir = "/home/photos";
$CGI::POST_MAX = 1024 * 5000;
my $safe_filename_characters = "a-zA-Z0-9_.-";
@images = qw (image1 image2 image3 image4);
foreach $image(@images) {
if ($input{$image}) {
$i++;
my $filename = "$input{$image}";
fatalError ("There was a problem uploading your photo (try a smaller file). $!") if ( !$filename );
my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' );
$filename = $name ._. $time . $extension;
$filename =~ tr/ /_/;
$filename =~ s/[^$safe_filename_characters]//g;
fatalError ("Filename contains invalid characters $!") unless ( $filename =~ /^([$safe_filename_characters]+)$/ );
my $upload_filehandle = "$input{$image}";
open ( UPLOADFILE, ">$upload_dir/$filename" ) or fatalError ("$!");
binmode UPLOADFILE;
while ( <$upload_filehandle> )
{
print UPLOADFILE;
}
close UPLOADFILE;
$imageinfo{$i} = "$filename";
}
}