PHP获取多个文件

PHP获取多个文件

问题描述:

I have an input of type file with property multiple. With this property I can select multiple files. How can I adress these files after submit with PHP?

Using this script and selcting multiple files, the output only contains 1 file:

  <?php
    print_r($_FILES);
  ?>

  <form  method="post" enctype="multipart/form-data">
     <input type="file" name='file' multiple >
     <input type="submit">
  </form>

Here is the output:

Array ( 
 [file] => Array ( 
        [name] => firefox.exe 
        [type] => application/octet-stream 
        [tmp_name] => /is/htdocs/user_tmp/wp10991132_7P7886URU4/phpO5UJ59 
        [error] => 0 
        [size] => 392136 
        ) 
 )

Where are the other files?

我的输入类型文件 strong>,属性多重 strong> 。 有了这个属性,我可以选择多个文件。 如何在使用PHP提交后对这些文件进行处理? p>

使用此脚本并选择多个文件,输出只包含1个文件: p>

 &lt;?php 
 print_r($ _ FILES); 
?&gt; 
 
&lt; form method =“post”enctype =“multipart / form-data”&gt; 
&lt; input type =“file  “name ='file'multiple&gt; 
&lt; input type =”submit“&gt; 
&lt; / form&gt; 
  code>  pre> 
 
 

以下是输出: p>

  Array(
 [file] =&gt; Array(
 [name] =&gt; firefox.exe 
 [type] =&gt; application / octet-stream  
 [tmp_name] =&gt; /是/ htdocs / user_tmp / wp10991132_7P7886URU4 / phpO5UJ59 
 [错误] =&gt; 0 
 [size] =&gt; 392136 
)
)
  code>   pre> 
 
 

其他文件在哪里? p> div>

You should use array as name of HTML input

<input type="file" name='file[]' multiple >

HTML:  
<form method="post" enctype="multipart/form-data">
  <input type="file" name="file[]" multiple >
  <input type="submit">
</form>

To get them in PHP as described here:
http://php.net/manual/en/features.file-upload.multiple.php

PHP:  

$first_file_name = $_FILES['file']['name'][0];
$second_file_name = $_FILES['file']['name'][1];

$first_file_tmp_name = $_FILES['file']['tmp_name'][0];
$second_file_tmp_name = $_FILES['file']['tmp_name'][1];

$first_file_size = $_FILES['file']['size'][0];
$second_file_size = $_FILES['file']['size'][1];
//and so on...

You can see here what browser versions support this possibility:
http://www.w3schools.com/tags/att_input_multiple.asp
(for instance multiple attribute is not supported under IE 10)