How do I make a multiple file upload?

Posted by Bluemagica on Stack Overflow See other posts from Stack Overflow or by Bluemagica
Published on 2011-01-02T14:36:24Z Indexed on 2011/01/02 14:54 UTC
Read the original article Hit count: 141

Filed under:

I am trying to make a multiple image uploader. The file upload fields are being added in the form dynamically using jquery. I tried making an array of the fields since I don't want to have a hidden field. so my generated upload fields look like

<input type="file" id="img0" name="img[]"/>
<input type="file" id="img1" name="img[]"/>
<input type="file" id="img2" name="img[]"/>
.....
..

And on the php side I did something like

if(isset($_FILES['img']))
{
    foreach($_FILES['img'] as $k=>$v)
    {
        if($v!="")
        {
            uploadImage($k,0,0,0,"content/gallery/");
        }
    }
}

Now I know I am way too wrong, since in that code I am looping through the 'img' file's properties instead of all images....but I have no idea how to fix this.

PS: uploadImage is a function I wrote which expects the file input field's name as the first parameter.

© Stack Overflow or respective owner

Related posts about php