Multiple file upload identification

KAD

I am using file upload input with multiple attribute. The output of my $_FILES is as follows:

 [kadFile] => Array
        (
            [name] => Array
                (
                    [0] => Txt1.txt
                    [1] => Doc1.docx
                )

            [type] => Array
                (
                    [0] => text/plain
                    [1] => application/vnd.openxmlformats-officedocument.wordprocessingml.document
                )

            [tmp_name] => Array
                (
                    [0] => C:\wamp\tmp\phpE515.tmp
                    [1] => C:\wamp\tmp\phpE525.tmp
                )

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

            [size] => Array
                (
                    [0] => 824
                    [1] => 768066
                )

        )

Is there a way to identify these files by giving them a specific name through javascript let's say or any other way so that they will be POST-ED as follows:

 [kadFile] => Array
            (
                [name] => Array
                    (
                        ["kadFile_txt1"] => Txt1.txt
                        ["kadFile_doc1"] => Doc1.docx
                    ) ...

I need to pass specific properties to each file by creating dynamic input fields when the files are selected, these fields have a naming convention, (the file input name + the selected file name + specific field identifier). At the server level I need to save each file and add these extra properties one shot.

Rasclatt

You can create an associative array if you want to as long as you preserve the the settings. Then treat $new in place of the $_FILES array, something like this:

foreach($_FILES['kadFile']['name'] as $key => $value) {
        // This is not the greatest of regex, but works for your example
        preg_match('/([^\.]+).([0-9a-zA-Z]{3})/',$value,$exp);
        $nKey   =   $exp[1];
        $new['kadFile']['name']["kadFile_".$nKey]       =   $value;
        $new['kadFile']['tmp_name']["kadFile_".$nKey]   =   $_FILES['kadFile']['tmp_name'][$key];
        $new['kadFile']['error']["kadFile_".$nKey]      =   $_FILES['kadFile']['error'][$key];
        $new['kadFile']['size']["kadFile_".$nKey]       =   $_FILES['kadFile']['size'][$key];

    }

echo print_r($new);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related