$db="editor";
$user="admin";
$pas="admin";
$conn=mysql_connect("localhost",$user,$pas) or die("连接错误");
mysql_select_db($db,$conn);
mysql_query("set names 'GB2312'");
$nba=$_FILES["bai"]["name"];
$tmpname=$_FILES["bai"]["tmp_name"];
$size=$_FILES["bai"]["size"];
$type=$_FILES["bai"]["type"];
$error=$_FILES["bai"]["error"];
if (file_exists("../upload/".$nba )){
echo "文件已存在";
}else {
foreach ($error as $key=>$val){
if($val==0){
move_uploaded_file($tmpname[$key],"../upload/" .rand().$nba[$key]);
$imgpath="../upload/" .rand().$nba[$key];
echo $imgpath;
$sql1 = "INSERT INTO news (title, content,imgpath) VALUES ('a','b','$imgpath')";
echo $nba[$key]."--------".$tmpname[$key]."----------".$size[$key]."--------------".$type[$key];
echo "
";
}
else {
echo "wrong!";}
}
}
?>
你的foreach只循环了一遍.
写的好乱啊,建议去找一个Jquery多图上传的控件来,很轻松几行代码就搞定。