PHP Multiple image upload.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
onyx3d
Forum Newbie
Posts: 1
Joined: Sat Feb 18, 2012 5:57 pm

PHP Multiple image upload.

Post 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.
xtiano77
Forum Commoner
Posts: 72
Joined: Tue Sep 22, 2009 10:53 am
Location: Texas

Re: PHP Multiple image upload.

Post 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.
Post Reply