|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39087 filetype() or is_dir() not recognizing a directory
Submitted: 2006-10-09 05:41 UTC Modified: 2006-10-09 22:49 UTC
From: scottayy at gmail dot com Assigned:
Status: Not a bug Package: Directory function related
PHP Version: 5.1.6 OS: Windows XP Pro SP2 Build 2600
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: scottayy at gmail dot com
New email:
PHP Version: OS:


 [2006-10-09 05:41 UTC] scottayy at gmail dot com
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.


Using this simple script to loop through the themes directory and get directory names:

Reproduce code:
//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;
			return false;
	} else
		return false;
	return $themes;

if($themes = get_available_themes())
	echo '<pre>';
	echo '</pre>';
} else
	echo 'No themes could be found.';

Expected result:
   [0] => crap,
   [1] => default

Actual result:
The function returns false because the array actually contains:


If I echo out $file during the while() loop, I see



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-09 05:47 UTC] 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 09:20 UTC] 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 for your work.
 [2006-10-09 09:46 UTC]
Please try using this CVS snapshot:
For Windows:

 [2006-10-09 09:47 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

 [2006-10-09 22:49 UTC] scottayy at gmail dot com
Sorry.  I have worked with these functions many -- many -- times.  I guess they just have always been in the directory I was already working in.  So, the failure seemed a bit odd to me in this situation.  Sorry for wasting your time and thank you for the quick responses!
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 25 21:01:29 2024 UTC