0

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?

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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 ++; } }
1

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

Comments

0

Shouldn't it be

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

Rather than

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

2 Comments

Nope, the files array has a somewhat weird behaviour, so it is correct.
Doh, and I thought that was easy points! ;) Gotta love PHP's internal consistency...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.