Forum Moderators: open

Message Too Old, No Replies

uploading images via email form

uploading more than one image

         

SoPretty

2:47 pm on Oct 28, 2005 (gmt 0)

10+ Year Member



Hi,

I have a contact form on my site that I want to modify so the sender is able to upload several photos to it before they submit it.

I found this via these forums:

<form name="formname" method="post" enctype="multipart/form-data" action="upload.asp">
<input type="file" name="filetoupload">
<input name="Submit" value="Submit" type="submit">

But it only allows for one image and appears to be a separate form altogether - I want the images sent with the rest of the form, not separately.

Does anyone know where I can find an example of a form that allows the upload of mulitple images and lets the sender submit them with the entire form?

Thanks!

rocknbil

6:46 pm on Oct 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The best way I've found to do this is when the form is called, first gather how many images they'll want to upload. from there, just dynamically build the upload form and file fields, insuring they all have unique names. Following is a perl example, my ASP is very dusty, but it can be done in any language:

## All query data is stored in %qs from a standard read/parse.
## Maximum number of pics allowed for upload?
$uploads_allowed = 5;

## If 0 images is not possible just start at 1.

if (! $qs{'num_pics'}) {
$form = qq¦
<form method="post" action="yourscript">
Please enter how many pics you will upload (if none, select 0.)
<select name="num_pics">
¦;
for $i (0..$uploads_allowed) {
$form .= qq¦<option value="$i">$i</option>\n¦;
}
$form .= qq¦
</select>
<input type="submit" value="Continue">
</form>
¦;
}

else {
$form = qq¦
<form method="post" enctype="multipart/form-data" action="yourscript">
<input type="hidden" name="num_pics" value="$qs{'num_pics'}">
¦;

## if number of pics is zero, it will do nothing here.
for $i (1..$qs{'num_pics'}) {
$label = 'File ' . $i;
$obj_name = 'file_' . $i;
$form .= qq¦$label: <input type="file" name="$obj_name"><br>\n¦;
}

$form .= qq¦
<input type="submit" name="submitButton" value="Upload">
</form>
¦;

When submitted on the server side, you would do the same sort of looping to figure out which fields contain file data.

SoPretty

8:32 pm on Oct 28, 2005 (gmt 0)

10+ Year Member



Thanks for your help! I'm not familiar with Perl but I am going to read up on it and see how that all works.

I asked my webhost and he said his server doesn't have any Microsoft code on it or anything that even smells of Microsoft, so the .asp code in my original post wouldn't work anyway. He suggested finding a precanned php script so I am going to have a looksee for that, too.

Thanks again! :o)

realHan1

5:22 pm on Nov 1, 2005 (gmt 0)

10+ Year Member



You could get them to zip their images and upload the zip. The your code can unzip them on the server and save the files wherever you want.

Han.