我有以下文件上传
<input type="file" name="files2[]" multiple onchange="readURL(this);" size="1" class="input-file" />
当设置files2时,我需要以某种方式用files2 []替换files []。
以下是(文件/文件)的内容:
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'];
}
如果我将此更改为以下内容,则始终满足条件,导致文件[]的内容也为空。
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文件和文件2是输入的混淆名称,清楚地意识到这一点;)
答案 0 :(得分:0)
以下似乎有效:
if (!empty($_FILES['files2']['name'][0])) {
$_FILES['files']=$_FILES['files2'];
}
不确定是否有更好的检查方法。