Forum Moderators: coopster

Message Too Old, No Replies

multiple image upload

         

lazarus

12:01 pm on Jul 9, 2003 (gmt 0)

10+ Year Member



hey, ive created a form to upload one image, and place the name of that image in a db, so i can call the name on other pages.

how can i use a form to allow upto 4 pics to be uploaded, and for their names to be placed in a db?

if you have any idea's i would appreciate it.

Dave

jatar_k

4:25 pm on Jul 9, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



All you do is replicate the form code that you already have for the single file field.

Then you just have to do your uploading for each seperate file.

I use this for multiple uploads on one form

while ($upcount <= $imgremain) {
echo "<b>Image",$upcount,"</b>";
echo "Description ",$upcount,": <input name=\"description",$upcount,"\" size=\"50\" maxlength=\"80\">";
echo "File ",$upcount,": <input type=\"file\" name=\"userfile",$upcount,"\"><br>&nbsp;";
$upcount++;
}

they are allowed a set number of uploads so it creates a file field for each remaining upload, hence the test in the while loop. Then in the script I have


while ($imagecounter <= $max_images) {
...lots of code missing...
if (move_uploaded_file($_FILES["userfile" . $imagecounter]['tmp_name'], $full_uploaddir . $tempic)) {
$desc = mysql_escape_string(${"description" . $imagecounter});
$iiq = "INSERT INTO listing_imgs VALUES (" . $newid . ",'" . $desc . "', " . $listing_id . ",'no',0,'none'," . $p_order . ",'" . $desc . "','','')";
mysql_query($iiq) or die(mysql_errno().": ".mysql_error()."<BR>");
} else {
echo "<b>",$_FILES['userfile']['name'],"</b> did not upload!";
die;
}
...lots of code missing...
$imagecounter++;
}

Where $imagecounter is incremented to control which image is being dealt with

I trimmed out a bunch of code out of both of those snippets(I may have even broken them) but you get the idea.

Birdman

11:05 pm on Jul 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

Here's another example of uploading multiple images [webmasterworld.com]. You have to scroll down the page to find the post called "Image upload and Thumbnail Generator".

Birdman

p.s. That script creates thumbnails too, just ignore that part.

jatar_k

11:26 pm on Jul 10, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



msg 29 in that thread

The one I use is a bashed, beaten and extended version of Birdman's great contribution. ;)

Birdman

3:10 am on Jul 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks jatar_k! That script is actually a bashed, beaten and extended version of an example from the manual and some other stuff I found.

I think I need to look at the mysql_escape_string part you added, because I still have problems when quotes are in the descrip.

willybfriendly

4:54 am on Jul 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have been struggling with this problem for a couple of weeks now. Serendipity that you folks give me an answer out of the blue. Thanks much!

WBF

lazarus

9:35 am on Jul 15, 2003 (gmt 0)

10+ Year Member



thanks a lot all, thats been a great help!