note 108694 added to function.is-dir
| From: | TrevorPott | Date: | Thu, 17 May 2012 22:58:54 +0000 |
| Subject: | note 108694 added to function.is-dir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-188051@lists.php.net to get a copy of this message | ||
When attempting to list directories other than the one the script is located in, be aware of the
peculiarities of is_dir's pathing requirements.
<?php
$dir = ".";
if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
if (is_dir($entry) === true){
echo "DIRECTORY: ".$entry."\n";
}else{
echo "FILE: ".$entry."\n";
}
}
}
closedir($handle);
}
?>
Will work fine for the directory you are currently inhabiting...but no other one.
Instead, try this:
<?php
$dir = "/some/other/dir";
if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
if (is_dir($dir."/".$entry) === true){
echo "DIRECTORY: ".$entry."\n";
}else{
echo "FILE: ".$entry."\n";
}
}
}
closedir($handle);
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 64.141.126.151
----
Manual Page -- http://www.php.net/manual/en/function.is-dir.php
Edit -- https://master.php.net/note/edit/108694
Del: integrated -- https://master.php.net/note/delete/108694/integrated
Del: useless -- https://master.php.net/note/delete/108694/useless
Del: bad code -- https://master.php.net/note/delete/108694/bad+code
Del: spam -- https://master.php.net/note/delete/108694/spam
Del: non-english -- https://master.php.net/note/delete/108694/non-english
Del: in docs -- https://master.php.net/note/delete/108694/in+docs
Del: other reasons-- https://master.php.net/note/delete/108694
Reject -- https://master.php.net/note/reject/108694
Search -- https://master.php.net/manage/user-notes.php