我想在单击按钮上传多个文件,如果我将任何图像留空或者我没有上传任何内容,则应该有默认图像。但代码无法正常工作:
<?php
date_default_timezone_set('Asia/Calcutta');
$date = date('Y-m-d');
$s1=$_FILES['image']['name'];
$s2=$_FILES['image1']['name'];
$s3=$_FILES['image2']['name'];
$s4=$_FILES['image3']['name'];
$s5=$_FILES['image4']['name'];
$s6=$_FILES['image5']['name'];
$s7=$_FILES['image6']['name'];
$s8=$_FILES['image7']['name'];
$s9=$_FILES['image8']['name'];
$s10=$_FILES['image9']['name'];
$path="images/".$s1;
$path1="images/".$s2;
$path2="images/".$s3;
$path3="images/".$s4;
$path4="images/".$s5;
$path5="images/".$s6;
$path6="images/".$s7;
$path7="images/".$s8;
$path8="images/".$s9;
$path9="images/".$s10;
move_uploaded_file($_FILES['image']['tmp_name'],$path);
move_uploaded_file($_FILES['image1']['tmp_name'],$path1);
move_uploaded_file($_FILES['image2']['tmp_name'],$path2);
move_uploaded_file($_FILES['image3']['tmp_name'],$path3);
move_uploaded_file($_FILES['image4']['tmp_name'],$path4);
move_uploaded_file($_FILES['image5']['tmp_name'],$path5);
move_uploaded_file($_FILES['image6']['tmp_name'],$path6);
move_uploaded_file($_FILES['image7']['tmp_name'],$path7);
move_uploaded_file($_FILES['image8']['tmp_name'],$path8);
move_uploaded_file($_FILES['image9']['tmp_name'],$path9);
$default_image = "images/default_img.png";
if(!($s1=="" ))
{
$q="insert into form(id, image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, date)values
('','$default_image','$path1','$path2','$path3','$path4','$path5','$path6','$path7','$path8','$path9','$date')";
}
else if(!($s2==""))
{
$q="insert into form(id, image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, date)values
('','$default_image','$path2','$path3','$path4','$path5','$path6','$path7','$path8','$path9','$date')";
}
else if(!($s3==""))
{
$q="insert into form(id, image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, date)values
('','$path','$path1','$default_image','$path3','$path4','$path5','$path6','$path7','$path8','$path9','$date')";
}
else if(!($s4==""))
{
$q="insert into form(id, image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, date)values
('','$path',$path1','$path2','$default_image','$path4','$path5','$path6','$path7','$path8','$path9','$date')";
}
else if(!($s5==""))
{
$q="insert into form(id, image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, date)values
('','$path','$path1','$path2','$path3','$default_image','$path5','$path6','$path7','$path8','$path9','$date')";
}
else if(!($s6==""))
{
$q="insert into form(id, image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, date)values
('','$path','$path1','$path2','$path3','$path4','$default_image','$path6','$path7','$path8','$path9','$date')";
}
else if(!($s7==""))
{
$q="insert into form(id, image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, date)values
('','$path','$path1','$path2','$path3','$path4','$path5','$default_image','$path7','$path8','$path9','$date')";
}
else if(!($s8==""))
{
$q="insert into form(id,image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, date)values
('','$path','$path1','$path2','$path3','$path4','$path5','$path6','$default_image','$path8','$path9','$date')";
}
else if(!($s9==""))
{
$q="insert into form(id, image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, date)values
('','$path','$path1','$path2','$path3','$path4','$path5','$path6','$path7','$default_image','$path9','$date')";
}
else if(!($s10==""))
{
$q="insert into form(id, image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, date)values
('','$path','$path1','$path2','$path3','$path4','$path5','$path6','$path7','$path8','$default_image','$date')";
}
else{
$q="insert into form(id, image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, date)values
('','$path','$path1','$path2','$path3','$path4','$path5','$path6','$path7','$path8','$path9','$date')";
}$e=mysql_query($q);
if($e>0)
{
header("location:registration.php?msg=insertion sucess");
}
else
{
header("location:registration.php?msg=insertion fail");
}
?>
答案 0 :(得分:0)
页面是什么样的?您可能需要发布更多信息(实际输出,来自服务器的任何错误消息,如果实际插入了行等),但如果页面为空白,我猜这可能是因为您的$s1
到$s9
变量实际上并不等于&#39;&#39;。尝试echo $s1;
,看看当该字段为空时输出是什么