tags:

views:

62

answers:

3

Hi there,

Got this working

$i = 0;  
 foreach ($_FILES["image"]["error"] as $key => $error) {
  if ($error == UPLOAD_ERR_OK) {
   $tmp_name = $_FILES["image"]["tmp_name"][$key];
   $image_name = $_FILES["image"]["name"][$key];
   $image.$i = move_uploaded_file($tmp_name, "uploads/$image_name");
   $i ++;
  }
 }

I cant seem to get the directory storing into the variables $image# any ideas?

+2  A: 

Why are oyu mixing usage of $_FILES and $HTTP_POST_FILES? Usage of the later suggests that you're using an old and outdated tutorial.

You'RE also not checking whether multiple files have been successfully transefered and using copy() for this purpose is not encouraged.

See move_uploaded_files() which has an example about handling multiple uploads.

johannes
Thanks, i have this code now, uploading works, but having trouble storing the destination in some variables, any ideas?$i = 0; foreach ($_FILES["image"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["image"]["tmp_name"][$key]; $image_name = $_FILES["image"]["name"][$key]; $image.$i = move_uploaded_file($tmp_name, "uploads/$image_name"); $i ++; } }
A: 

Shouldn't it be

$_FILES['image'][$i]['name']

Rather than

$_FILES['image']['name'][$i]
MatW
Nope, the files array has a somewhat weird behaviour, so it is correct.
Hanse
Doh, and I thought that was easy points! ;) Gotta love PHP's internal consistency...
MatW
A: 

I got this working in the end by creating an array and storing the values in this array