2018年1月24日 星期三

PHP的測試 (2) 檔案上傳

用9個檔案上傳的方格

<form id="upForm"  action="test01.php" method="post" enctype="multipart/form-data">
<?PHP
for ($i=1;$i<10;$i++) {
  echo "$i <input name='l1upfile[$i]' type='file' ><br>";

}

?>
<input type="submit" value="上傳" />
</form>


只有 1,4輸入檔案時,可得到底下的$_FILES陣列

Array ( [l1upfile] => Array ( [name] => Array ( [1] => number.sb2 [2] => [3] => [4] => 抽座號.sb2 [5] => [6] => [7] => [8] => [9] => ) [type] => Array ( [1] => application/octet-stream [2] => [3] => [4] => application/octet-stream [5] => [6] => [7] => [8] => [9] => ) [tmp_name] => Array ( [1] => /tmp/phpRwv3Pk [2] => [3] => [4] => /tmp/php3wqacg [5] => [6] => [7] => [8] => [9] => ) [error] => Array ( [1] => 0 [2] => 4 [3] => 4 [4] => 0 [5] => 4 [6] => 4 [7] => 4 [8] => 4 [9] => 4 ) [size] => Array ( [1] => 53048 [2] => 0 [3] => 0 [4] => 53054 [5] => 0 [6] => 0 [7] => 0 [8] => 0 [9] => 0 ) ) )


補充

單一檔案上傳
<input name='upfile1[0]' type='file' />
<input name='upfile1[1]' type='file' />
和多重檔案上傳
<input name='upfile2[]' type='file' multiple="" />
得到的 $_FILES陣列是相同的

Array('name'=>array(0=>...,1=>...),
      'type'=>array(0=>...,1=>...),
      'tmp_name'=>array(0=>...,1=>...),
      'error'=>array(0=>...,1=>...),
      'size'=>array(0=>...,1=>...))

沒有留言:

張貼留言