Multiple File Input

File inputs can have an attribute of "multiple" which then allows multiple files to be selected in the file section dialog box. Firefox 3.6+ and WebKit browsers only are supporting it so far. Unfortunately the "multiple files" need to be within the same folder, as there is no interface for selecting one, moving folders, and selecting another.

<form method="post" action="upload.php" enctype="multipart/form-data">
  <input name='uploads[]' type="file" multiple>
  <input type="submit" value="Send">
</form>

Note that the "name" of the file input has brackets at the end of it. This isn't required per the spec but is required to process the multiple files.

In PHP, you can then loop through the data as an array:

foreach ($_FILES['uploads']['name'] as $filename) {
    echo '<li>' . $filename . '</li>';
}

Comments

  1. User Avatar
    Banago
    Permalink to comment#

    Very great snippet – thanks for it.

  2. User Avatar
    Fabricio Reinert
    Permalink to comment#

    that only work with 3 files? o.0

    • User Avatar
      DonTermi
      Permalink to comment#

      and in Chrome it works too.

    • User Avatar
      tresorunikin
      Permalink to comment#

      Fabricio Reinert : CHECK YOUR php.ini FILE, or use the function max_file_uploads() to set the value higher than 3…

  3. User Avatar
    ridcully
    Permalink to comment#

    The brackets are only required if you use PHP in the backend. For Java they are not necessary…

  4. User Avatar
    Hung Nguyen

    How about IE?

  5. User Avatar
    david
    Permalink to comment#

    how to delete one file of select files?

  6. User Avatar
    Coach
    Permalink to comment#

    Uninstall IE now.

Submit a Comment

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

icon-closeicon-emailicon-linkicon-logo-staricon-menuicon-searchicon-staricon-tag