0

我有以下文件上传

<input type="file" name="files2[]" multiple onchange="readURL(this);" size="1" class="input-file" />

设置 files2 时,我需要以某种方式将 files[] 替换为 files2[]。

以下是(文件/文件)的内容:

Array ( [files] => Array ( [name] => Array ( [0] =>c GIF.gif ) [type] => Array ( [0] => image/gif ) [tmp_name] => Array ( [0] => C:\Windows\Temp\phpF943.tmp ) [error] => Array ( [0] => 0 ) [size] => Array ( [0] => 9921 ) ) [files2] => Array ( [name] => Array ( [0] => 14 beresford.png [1] => combination-boilerc2.jpg ) [type] => Array ( [0] => image/png [1] => image/jpeg ) [tmp_name] => Array ( [0] => C:\Windows\Temp\phpF944.tmp [1] => C:\Windows\Temp\phpF955.tmp ) [error] => Array ( [0] => 0 [1] => 0

我已经尝试了以下条件,但似乎没有满足

if (!empty($_FILES['files2']['error'][0])) {

$_FILES['files']=$_FILES['files2'];

} 

如果我将其更改为以下条件,则始终满足条件,导致 files[] 的内容也为空。

if (!empty($_FILES['files2'])) { //this is always reached even if files 2 is empty...

    $_FILES['files']=$_FILES['files2'];

    } 

Array ( [files] => Array ( [name] => Array ( [0] => ) [type] => Array ( [0] => ) [tmp_name] => Array ( [0] => ) [error] => Array ( [0] => 4 ) [size] => Array ( [0] => 0 ) ) [files2] => Array ( [name] => Array ( [0] => ) [type] => Array ( [0] => ) [tmp_name] => Array ( [0] => ) [error] => Array ( [0] => 4 ) [size] => Array ( [0] => 0 ) ) ) 0 is an Invalid file type: 

*note files 和 files2 是输入的混淆名称,清楚地意识到这一点;)

4

1 回答 1

0

以下似乎有效:

if (!empty($_FILES['files2']['name'][0])) {

    $_FILES['files']=$_FILES['files2'];

    } 

不确定是否有更好的检查方法。

于 2013-08-21T11:51:57.317 回答