Page 1 of 1

PHP Multiple image upload.

Posted: Sat Feb 18, 2012 6:11 pm
by onyx3d
Hi, I am currently having problems with uploading multiple images using php scripts.
The problem is that the script runs successfully but it doesn't show up in the folder I specified.
Here is the code for the form and the php script.

Code: Select all

echo "<label class='desc' for='prodimage'>Product Image:</label>
<input type='file' name='image[]' id='file1' tabindex='5'/><br />
<input type='file' name='image[]' id='file2' tabindex='6' /><br />
<input type='file' name='image[]' id='file3' tabindex='7' /><br />
<input type='file' name='image[]' id='file4' tabindex='8' /><br />";
In productquery.php file...

Code: Select all

$target = "prodimages/";
$file = $target . basename($_FILES['image']['name'][0]);
$file = $target . basename($_FILES['image']['name'][1]);
$file = $target . basename($_FILES['image']['name'][2]);
$file = $target . basename($_FILES['image']['name'][3]);

if (($_FILES["image"]["size"][0] > 500000) || ($_FILES["image"]["size"][1] > 500000) || ($_FILES["image"]["size"][2] > 500000) || 
($_FILES["image"]["size"][3] > 500000))
{
header("location:product.php?message=4");
}

move_uploaded_file($_FILES['image']['tmp_name'], $file);
I am using a free web hosting service.
Please can anyone see me through this and help me with the complete codes to upload the files arranged and successfully...

Kind Regards.

Re: PHP Multiple image upload.

Posted: Sun Feb 19, 2012 7:13 pm
by xtiano77
Onyx,

I could be mistaken, but I belive the problem is that you are not indexing the "tmp_name" file to be moved as you did above in order to get the true file's name. For example and assuming you are using a loop:

Code: Select all

move_uploaded_file($_FILES["image"]["tmp_name"][iterator], $file);
Hope this helps.