I want to make multiple image upload in a one row but it creates two row, one is exactly that I want but the other one is null. Why it creates two row?
<?php
$dir="img";
$imgList = array();
$files_count=count($_FILES['files']['name']);
for($i=0;$i<$files_count;$i++){
if(!empty($_FILES['files']['name'][$i]))
{
move_uploaded_file($_FILES['files']['tmp_name'][$i],$dir."/".$_FILES['files']['name'][$i]);
$file_name = $_FILES['files']['name'][$i];
array_push($imgList,$file_name);
}
}
$imgs = implode(",",$imgList);
mysqli_query($connect,"insert into episodes (Id,images) values ('','$imgs')");
?>
Try this code :
<?php
if(isset($_FILES['files'])) {
$dir="img";
$imgList = array();
$files_count=count($_FILES['files']['name']);
for($i=0;$i<$files_count;$i++){
if(!empty($_FILES['files']['name'][$i]))
{
move_uploaded_file($_FILES['files']['tmp_name'][$i],$dir."/".$_FILES['files']['name'][$i]);
$file_name = $_FILES['files']['name'][$i];
array_push($imgList,$file_name);
}
}
$imgs = implode(",",$imgList);
mysqli_query($connect,"insert into episodes (Id,images) values ('','$imgs')");
}
?>
You just need to check if file is set or not.