Multiupload with PHP/JavaScript

2019-09-14 04:42发布

Are there any solutions to upload multiple files at once without flash? :)

Not like that: choose one file, it goes to the stock, choose second file, it goes to the stock and than upload. But choose at once all needed files and upload them.

2条回答
贼婆χ
2楼-- · 2019-09-14 05:06

HTML5 supports multiple files, by specifying the "multiple" attribute on the input.

Give the input a name attribute ending in square brackets (i.e. "myfileinput[]") and it will appear to PHP exactly the same as if there were two inputs called the same thing on the page.

This obviously doens't work in legacy browsers, however lack of support for multiple file uploads could be detected via JS, and multiple file inputs created via JS.

查看更多
Emotional °昔
3楼-- · 2019-09-14 05:12

You can have multiple file input fields:

<input type="file" name="file1" />
<input type="file" name="file2" />
etc...

or

<input type="file" name="file[]" />
<input type="file" name="file[]" />

They can be created dynamically via Javascript, or created in advance from the server. Either way, you get multiple files uploaded, though only file per input field.

The first option will work as expected. You'll get one $_FILES array entry per file in PHP. The other option, with the array notation, works a bit counter-intuitively. You get something that looks like

$_FILES = array(
   'file' => array(
       'name' => array(
            0 => 'name of first file',
            1 => 'name of second file
        ),
        'type => array(
            0 => 'mime type of first file',
            1 => 'mime type of second file',
     etc....
查看更多
登录 后发表回答