I have code below and it is working well.It allows files to be uploaded to the database and at the same time moved to the designated folder.However,when i only upload one file, all the other three database columns values are inserted of this type . aw3er45tr56. without file extension .I need a kind person to assist me solve these.
if(!empty($DescAd)){
$fileData1 = pathinfo(basename($_FILES["AdImage1"]["name"]));
$fileData2 = pathinfo(basename($_FILES["AdImage2"]["name"]));
$fileData3 = pathinfo(basename($_FILES["AdImage3"]["name"]));
$fileData4 = pathinfo(basename($_FILES["AdImage4"]["name"]));
$fileName1 = uniqid() . '.' . $fileData1['extension'];
$fileName2 = uniqid() . '.' . $fileData2['extension'];
$fileName3 = uniqid() . '.' . $fileData3['extension'];
$fileName4 = uniqid() . '.' . $fileData4['extension'];
$target_path1 = 'BusinessAdsUploads/'. $fileName1;
$target_path2 = 'BusinessAdsUploads/'. $fileName2;
$target_path3 = 'BusinessAdsUploads/'. $fileName3;
$target_path4 = 'BusinessAdsUploads/'. $fileName4;
while(file_exists($target_path1,$target_path2,$target_path3,$target_path4))
{
$fileName1 = uniqid() . '.' . $fileData['extension'];
$fileName2 = uniqid() . '.' . $fileData['extension'];
$fileName3 = uniqid() . '.' . $fileData['extension'];
$fileName4 = uniqid() . '.' . $fileData['extension'];
$target_path1 = 'BusinessAdsUploads/'. $fileName1;
$target_path2 = 'BusinessAdsUploads/'. $fileName2;
$target_path3 = 'BusinessAdsUploads/'. $fileName3;
$target_path4 = 'BusinessAdsUploads/'. $fileName4;
}
move_uploaded_file($_FILES['AdImage1']['tmp_name'],$target_path1);
move_uploaded_file($_FILES['AdImage2']['tmp_name'],$target_path2);
move_uploaded_file($_FILES['AdImage3']['tmp_name'],$target_path3);
move_uploaded_file($_FILES['AdImage4']['tmp_name'],$target_path4);
$query="insert into `MyAds` values('','$bisnaId','$user_id','$Category','$subCategory','$fileName1','$fileName2','$fileName3','$fileName4','$ItemTitle','$DescAd','$AdPrice','Personal Business')";
if($query_run=mysql_query($query)){
header('location:PreviewBisnaAd.php');
}
}