Try something like this inside the while :
if ($file != "." && $file != ".." && !is_dir($file) {
$images[] = $dir . '/' . $file;
}
Frage
I use the code suggested here https://stackoverflow.com/a/18316453
This is what I have now.
<?php
$dir = "sliders/slides";
$images = array();
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if (!is_dir($dir.$file)) $images[] = $dir . '/' . $file;
}
closedir($dh);
}
}
echo json_encode($images);
?>
My result includes 2 extra items
sliders/slides/.
sliders/slides/..
which makes my slider having 2 extra blank slides
How can I filter the result to show only .jpg and .png files in order to remove /.
and /..
be included in the results
I'm trying to create sliders that gets images from a folder
Thanks
Lösung
Try something like this inside the while :
if ($file != "." && $file != ".." && !is_dir($file) {
$images[] = $dir . '/' . $file;
}