Php 上载多个文件,如果我将任何图像留空或不';不要上传任何东西,应该有一个默认的图像

Php 上载多个文件,如果我将任何图像留空或不';不要上传任何东西,应该有一个默认的图像,php,mysql,Php,Mysql,我想通过单击一个按钮上传多个文件,而且如果我将任何图像留空,或者如果我不上传任何内容,默认图像应该在那里。但代码工作不正常: <?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['imag

我想通过单击一个按钮上传多个文件,而且如果我将任何图像留空,或者如果我不上传任何内容,默认图像应该在那里。但代码工作不正常:

<?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");
}
?>

页面是什么样子的?您可能需要发布更多信息(实际输出、来自服务器的任何错误消息、是否实际插入了行等),但如果页面为空,我猜可能是因为您的
$s1
$s9
变量实际上不等于“”。尝试
echo$s1
并查看字段留空时的输出结果

您好,欢迎来到StackOverflow。请花些时间阅读帮助页面,特别是命名和的部分。更重要的是,请阅读。您可能还想了解。顺便说一句,这段代码确实需要重构,添加一些数组和循环,例如
$path
创建、调用
移动上传的文件等。您好。。。。。。。我们有10个上传选项,我们想上传前5张图片。并希望保持REST5上传选项为空。第6个选项仅选取我们设置的默认图像作为空图像,其余4个选项不选取我们设置的Deafolt图像作为空选项。。可能是“如果”条件不能正常工作。请尽快给出你的观点,我明白你的问题。请考虑重构这个代码,它是非常长的和重复的,使用数组的值和循环重复数组。图6是唯一显示的一个,因为else-if,删除每个if语句中的else将使第9个语句显示默认值。您需要验证每个
s
值是否为null或空,并基于此为路径指定默认路径。