Forum Moderators: open

Message Too Old, No Replies

Adding image paths to MySql

How to add numerous image paths at once

         

wheelie34

11:59 am on Oct 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all

I am trying to upload multiple image paths and images to a mysql database, heres what I have so far

$file_dir = "/home/virtual/site31/fst/var/www/html/images";
$file_url = "http://www.example.com/images";

foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name = $_FILES["pictures"]["name"][$key];
move_uploaded_file($tmp_name, "$file_dir/$name");
$result = "$file_url/$listingnum-$name";
}
}

$sql="insert into data values (' ', '$result')";

#$listingnum grabs the last entry's number fine

The form has 10 of these
<input name="pictures[]" type="file">

Currently it only adds the last image in the loop, images are uplodaded fine its just I need to write their URL to the database for calling later.

Any advice much appreciated, thanks

coopster

10:05 pm on Oct 12, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would assume you need to move your INSERT inside your loop so you can get the correct url name and/or filename into your database for each iteration.