Reputation: 658
Guys have a problem don't know why this is not working, i have file input field which can upload multiple images.
this is my form
<form method="post" action="" enctype="multipart/form-data">
<input name="images[]" type="file" multiple="multiple">
<input type="submit" name="test" value="test"/>
</form>
If i submitted the code without selecting any files, i need to display an error message. Here is my php code
if(!empty($_FILES['images']['name'])){
foreach($_FILES['images']['name'] as $key =>$value){
//other code
}
}else{
echo 'No images have been selected';
}
but this won't work any idea why is that..?
Upvotes: 1
Views: 86
Reputation: 796
Try this:
$hasUpload = false;
if(isset($_FILES['images']['name'])){
foreach($_FILES['images']['name'] as $key => $value){
if(!empty($value)) {
// some codes here
$hasUpload = true;
}
}
}
if (!$hasUpload) {
echo 'No images have been selected';
}
Upvotes: 5