CodeIgniter Forums
javascript + multiple file uploads - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: javascript + multiple file uploads (/showthread.php?tid=8091)



javascript + multiple file uploads - El Forum - 05-05-2008

[eluser]nikefido[/eluser]
There's a few things going wrong here, and I have a feeling I'm going about this in a way that's not fully compatible with CI:

1) I have one file input named "userfile[]"
2) By clicking a link, users can create more file inputs (dynamically via javascript) - up to 10 total. These are all named "userfile[]"
3) IE seems to be reading these extra file inputs while FF does not! (yeah, that's right...IE is working, FF is not...weird)

print_r($_FILES):
Code:
//IE
Array
(
    [userfile] => Array
        (
            [name] => Array
                (
                    [0] => PAS-MIGRATION-42608.doc
                    [1] => arrows.gif
                )

            [type] => Array
                (
                    [0] => application/msword
                    [1] => image/gif
                )

            [tmp_name] => Array
                (
                    [0] => /tmp/phpA8XDk4
                    [1] => /tmp/phpIcfbcT
                )

            [error] => Array
                (
                    [0] => 0
                    [1] => 0
                )

            [size] => Array
                (
                    [0] => 33280
                    [1] => 2288
                )
        )
)


//FF
Array
(
    [userfile] => Array
        (
            [name] => Array
                (
                    [0] => arrows.gif
                )

            [type] => Array
                (
                    [0] => image/gif
                )

            [tmp_name] => Array
                (
                    [0] => /tmp/phpEKihEi
                )

            [error] => Array
                (
                    [0] => 0
                )

            [size] => Array
                (
                    [0] => 2288
                )
        )
)

Now, assuming I can change the javascript (to basically do the same thing but work in FF), and the array always looks like it does in IE...is that compatible with CI's file upload function? (it looks like CI's upload function would take indivisual $_FILE['userfile'] arrays but IE is showing more than one item per sub category within a single $_FILE['userfile'] obj...if that makes any sense)


javascript + multiple file uploads - El Forum - 05-05-2008

[eluser]nikefido[/eluser]
So, I discovered the javascript problem (firefox is very picky about dynamic form elements and nested form elements...click here for more info )

Now, I have a $_FILES array that that looks like the IE one in the post above...however, that doesn't seem compatible with using CI's upload function:

Code:
$this->upload->do_upload($field_name); //takes a field name, such as: $_FILES['fieldName']

now, I thought I'd have an array of files such as: $_FILE['userfile'][0], $_FILE['userfile'][1] and so forth...
However, get the array above (IE one) that has $_FILE['userfile']['name'][0] & $_FILE['userfile']['name'][1]

So, it looks like I might have to do some hacking / extending of CI's file uploading class?

Of course, an "easier" way might be to use different field names, but ... it's just not as clean...but I guess I have to do what I have to do...