I've finally found a way to get all the files from a folder to display on the site but for some reason it always displays 3 Div's that are empty and i really mean empty not some dots like in this post:
php scandir produces extra elements (2 dots)
Even without having any files in the folder. As seen on the picture
Does anyone have an idea why it behaves this way? I've included the code snippet that is causing the issue i think.
<div class="margin">
<div class="left js-equal-height" >
<h2>Recent nieuws</h2>
<?php
$dir = 'Nieuws';
$file_display = ['txt'];
$value = 0;
if (file_exists($dir) == false) {
return ["Directory \'', $dir, '\' not found!"];
} else {
$dir_contents = scandir($dir);
foreach ($dir_contents as $file) {
$img = basename($file, ".txt") . ".png";
$src = 'Nieuws/pics/'.$img;
echo '<div class="frontNieuws">';
if (@getimagesize($src)) {
echo '<img class="nieuwsFoto"
src="Nieuws\pics\\' . $img . '" alt="Nieuwsfoto">';
} else {
echo '<img class="nieuwsFoto"
src="Nieuws\pics\default.png" alt="Nieuwsfoto">';
}
echo file_get_contents($dir . '/'. $file,
false, null, 0, 200) . " ... Lees meer!";
echo '</div>';
}
}
?>