ワンクリックで複数のファイルをアップロードしたい場合や、私が何かをアップロードしなければ、デフォルトのイメージがそこにあるはずです。しかし、コードは正常に動作していません。複数のファイルをアップロードし、画像を空白にしても何もアップロードしない場合は、デフォルトの画像がそこにあるはずです
<?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");
}
?>
こんにちは、歓迎、StackOverflow。ヘルプページ、特に[ここではどのトピックについて聞かせていただけますか?](http://stackoverflow.com/help/on-topic)と[質問しないでください。」](http://stackoverflow.com/help/dont-ask)。さらに重要なことは、[Stack Overflow question checklist](http://meta.stackexchange.com/q/156810/204922)をお読みください。また、[最小、完全、および検証可能な例](http://stackoverflow.com/help/mcve)についても知りたいことがあります。 –
ところで、このコードは実際にはリファクタリングが必要で、 '$ path'の作成や' move_uploaded_file'などの呼び出しのためにいくつかの配列とループを追加します。 –