input file用了multiple属性 而且选择了多张图片 PHP该怎么上传?

2025-04-05 16:50:27
推荐回答(1个)
回答1:

其实就那两个函数
is_uploaded_file()和move_uploaded_file()
是循环上传的。你打印下$_FILES这个超全局数组就明白了。下面我的测试代码上传图片的:




无标题













$path=$_SERVER['DOCUMENT_ROOT'].'test2/';
if(!empty($_FILES)){
echo "aaaa";
if(is_uploaded_file($_FILES['images']['tmp_name'][0])){
echo "1111";
exit;
}

foreach($_FILES['images']['tmp_name'] as $k=>$v){
if(is_uploaded_file($_FILES['images']['tmp_name'][$k])){
$save=$path.$_FILES['images']['name'][$k];
echo $save."
";
if(move_uploaded_file($_FILES['images']['tmp_name'][$k],$save)){
echo "上传成功!";
}
}
}
echo "
";
print_r($_FILES);
echo "
";
}

?>