Jump to content

[SOLVED] Upload Array please help!


iceblox

Recommended Posts

Hi guys,

 

I have an upload image script which works on array, allowing you to set a max number of images. That part is all fine but im having trouble with getting it into a mysql database. I have worked it out if you just want each file as a new row. But what I want to do is save each image to a specfic column in the table.

 

For Example I have allowed a max of 6 images and have 6 colums in the table named img1 img2 etc and i want img 1-6 from the array into each of those. Whilst keeping them on the same row.

 

This is my Uploading code

 


while(list($key,$value) = each($_FILES[images][name]))
{
if(!empty($value)){ 

$filename = $value;

$add = "images/$filename";

copy($_FILES[images][tmp_name][$key], $add);
}
}


$result = $db->sql_query("INSERT INTO cars (MakeName, CarName, MakeID, CarType, Text, Img1, Img2, Img3, Img4, Img5, Img6, ActiveImg, caractive) VALUES
				('".forSql($_POST["MakeName"])."', '".forSql($_POST["CarName"])."', '".forSql($_POST["MakeID"])."', '".forSql($_POST["CarType"])."', '".forSql($_POST["text"])."', '$filename', '$filename', '$filename', '$filename', '$filename', '$filename', '$ActiveImg', '".forSql($_POST["active"])."')");

 

 

I have tried [$Key] after file name and without the [] but im not very good with arrays so im not sure of the output. Any help would be appreciated.

 

Thanks Phil

Link to comment
Share on other sites

Just a heads up, that's not exactly good practice in terms of database design. I'd suggest you create two more tables, image and image_car, image would contain the fields id,path and image_car would have id,image_id,car_id. You'd then "link" your images to your cars using the image_car table. This way you could attach as many or as little images as you wish...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.