Is there a glitch with opendir / readdir?
Here's my PHP code:
<?php
// Enumerate the directories in styles
$styles_dir = 'styles/';
if($handle = opendir($styles_dir))
{
while(FALSE !== ($file = readdir($handle)))
{
echo $file . '(' . is_dir($file) . ')<br>';
}
}
?>
Here are the directories in styles
:
http://files.quickmediasolutions.com/php.jpg
And here's the output:
.(1) ..(1) forest() industrial()
Why not catalogs forest
and industrial
?
+2
a source to share
2 answers
You need a directory name prefix for the filename as it is_dir
works relative to the current directory.
Edit
echo $file . '(' . is_dir($file) . ')<br>';
to
echo $file . '(' . is_dir("$styles_dir/$file") . ')<br>';
Alternatively, you can change the directory to $styles_dir
using chdir and then your current code will work.
+1
a source to share