I have a php function that allows me to delete images from a certain directory. Now my problem is that in my code, i can see the index.php file listed, and i only want to show the images under it. Here is my full code:
$fid= $_POST['fid'];
if (("submit")&&($fid != "")) {
foreach($fid as $rfn) {
$remove = "$dir/$rfn";
unlink($remove);
}
}
$handle=opendir($dir);
while (($file = readdir($handle))!== false){
if ($file != "." && $file != "..") {
$size = filesize("$dir/$file");
$list .= '<div class="col-md-3 text-center" style="margin-top:20px;">';
$list .= '<img src="../inc/img/galeria/'.$file.'" class="rounded" width="100%" height="250px">';
$list .= '<br><br>';
$list .= '<input type="checkbox" class="form-control" name="fid[]" value="'.$file.'">';
$list .= '</div>';
}
}
closedir($handle);
echo $list;
Now this code works just fine, the problem is it lists everything inside the directory and i want to show only the jpg, jpeg, gif or png files inside of that directory. Thanks in advance guys.