Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

upload multiple images

Status
Not open for further replies.

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.

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";
}
}
 
More info....

i added a check to the script to display (on the results page) the upload_filehandle and the image path that shows in the upload form.

the path to the image C:/..... doesn't show. i guess it's stripped during form processing. how do i get around that?

i'm testing the script in IE8.

thanks again.
 
Hello,

Does your form contain the enctype attribute? E.g.

Code:
<form action="script.pl" enctype="multipart/form-data" method="post">

Chris
 
let me find a rock to crawl under....

i forgot method=post - aarrrgh!

i must have checked the form tag a thousand times - mostly concerned with the 'enctype'. i copied/pasted it from several different sources, re-typed it, used single quotes/double quotes, etc.

thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top