I want to count
number of uploaded file but I'm unable to get the error if no file had been uploaded. Here is my code for reference:
html
<input type="file" name="file[]" class="filestyle" data-buttonText="Quotation 1" multiple="multiple">
php
$total = count($_FILES['file']['name']);
if($total > '2'){
for($i=0; $i<$total; $i++){
$tmpFilePath = $_FILES['file']['tmp_name'][$i];
if($tmpFilePath != ""){
$shortname = $_FILES['file']['name'][$i];
$filePath = "uploads/" . date('d-m-Y-H-i-s').'-'.$_FILES['file']['name'][$i];
if(!$msgError && move_uploaded_file($tmpFilePath, $filePath)){
// insert to db and success msg
}
}
} elseif($total < '4') {
$msgError[] = "Need to upload 3 Quotations";
}
if(isset($msgError)){
$msgErrorString = implode(",",$msgError);
header("Location: pr_form.php?msgError=".$msgErrorString."");
}
If user upload less than 3 files, the error will not appear. I have other validations for user input. Everything is working except for the file validation. May I know why?