How to upload multiple files using one file input element

后端 未结 3 1019
半阙折子戏
半阙折子戏 2020-12-04 15:47

I\'m trying to use one file input element to upload multiple files to Drive using html form. This seems to work only for one file, although the file picker allows selecting

3条回答
  •  爱一瞬间的悲伤
    2020-12-04 16:46

    I'm using possibility to send array of files. Just add [] to name atrribute:

    // etc.

    You will have array of arrays in $_FILES

    Array
    (
        [files] => Array
            (
                [name] => Array
                    (
                        [0] => 1.png
                        [1] => 2.png
                    )
    
                [type] => Array
                    (
                        [0] => image/png
                        [1] => image/png
                    )
    
                [tmp_name] => Array
                    (
                        [0] => /tmp/phpDQOZWD
                        [1] => /tmp/phpCELeSw
                    )
    
                [error] => Array
                    (
                        [0] => 0
                        [1] => 0
                    )
    
                [size] => Array
                    (
                        [0] => 32209
                        [1] => 64109
                    )
    
            )
    
    )
    

    Of course, you you'll have to upload them one by one. Not convenient to a large number of files, but works in all browsers. For example,using jQuery you can add one more input each time last files[] input was changed.

    function addOneMoreInput() {
        $('input[type=file]').last().change(function() {
            $(this).after('');
            $(this).off('change');
            addOneMoreInput();
        });
    }
    addOneMoreInput();
    

提交回复
热议问题