Multiupload with PHP/JavaScript

坚强是说给别人听的谎言 提交于 2019-12-25 08:30:04

问题


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.


回答1:


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.




回答2:


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....


来源:https://stackoverflow.com/questions/5211848/multiupload-with-php-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!