note 44697 deleted from function.is-dir by aidan
| From: | aidan@php.net | Date: | Sat, 14 Aug 2004 09:30:00 +0000 |
| Subject: | note 44697 deleted from function.is-dir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74620@lists.php.net to get a copy of this message | ||
Note Submitter: Ross Barefoot
----
To make sure you get a true on is_dir you have to use the path. For example...
I banged my head on a situation like this for a while:
<?php
if ($handle = opendir($_SERVER["DOCUMENT_ROOT"]."/img")) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($file)){
echo "Dir: ".$file;
}
else
{
echo "File: ".$file;
}
echo "<br />";
}
}
closedir($handle);
clearstatcache();
}
?>
It always reads as a file even if one of the entries is a directory. The problem is that it has to
see the whole path to recognize a directory. Thus the correct way is like this:
<?php
if ($handle = opendir($_SERVER["DOCUMENT_ROOT"]."/img")) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
+ $path = $_SERVER["DOCUMENT_ROOT"]."/img" . "/"
. $file;
! if (is_dir($path)){
echo "Dir: ".$file;
}
else
{
echo "File: ".$file;
}
echo "<br />";
}
}
closedir($handle);
clearstatcache();
}
?>
By the way, I found the solution on the PHP general mailing list.