×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

upload multiple images

upload multiple images

upload multiple images

(OP)
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";
}
}
 

RE: upload multiple images

(OP)
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.

RE: upload multiple images

Hello,

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

CODE

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

Chris

RE: upload multiple images

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close