#39087 [Opn->Fbk]: filetype() or is_dir() not recognizing a directory
| From: | tony2001@php.net | Date: | Mon, 09 Oct 2006 09:46:45 +0000 |
| Subject: | #39087 [Opn->Fbk]: filetype() or is_dir() not recognizing a directory | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-103285@lists.php.net to get a copy of this message | ||
ID: 39087
Updated by: tony2001@php.net
Reported By: scottayy at gmail dot com
-Status: Open
+Status: Feedback
Bug Type: Directory function related
Operating System: Windows XP Pro SP2 Build 2600
PHP Version: 5.1.6
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5.2-win32-latest.zip
Previous Comments:
------------------------------------------------------------------------
[2006-10-09 09:20:13] judas dot iscariote at gmail dot com
Please, go and get a couple of cofee :) this is of course not a bug,
but the expected behaviuor.
your code is checking if the $file dir, exists in the **current
directory** and **not** in the "themes" directory ;P
you need to prepend the **base directory** name in the loop.
I suggest you try something like
http://www.php.net/~helly/php/ext/spl/directoryfilterdots_8inc-source.html
for your work.
------------------------------------------------------------------------
[2006-10-09 05:47:59] scottayy at gmail dot com
Sorry, I forgot to mention that when looping through, '.' and '..' are
recognized as directories with filetype() and is_dir(), but the
directories I created are not.
------------------------------------------------------------------------
[2006-10-09 05:41:27] scottayy at gmail dot com
Description:
------------
PHP fails to recognize directories when looping through a directory.
filetype() says lstat() fails, and is_dir() returns false.
I have the following directory structure.
/
/themes/
/themes/crap/
/themes/default/
Using this simple script to loop through the themes directory and get
directory names:
Reproduce code:
---------------
<?php
//gather available themes
function get_available_themes()
{
if($handle = @opendir('themes'))
{
$themes = array();
while(false !== ($file = readdir($handle)))
{
if(is_dir($file) && ($file != '.' && $file != '..'))
{
$themes[] = $file;
}
}
if(empty($themes))
{
return false;
}
} else
{
return false;
}
return $themes;
}
if($themes = get_available_themes())
{
echo '<pre>';
print_r(get_available_themes());
echo '</pre>';
} else
{
echo 'No themes could be found.';
}
?>
Expected result:
----------------
Array
(
[0] => crap,
[1] => default
)
Actual result:
--------------
The function returns false because the array actually contains:
Array
(
)
If I echo out $file during the while() loop, I see
.
..
crap
default
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=39087&edit=1