|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19658 is_dir or is_file doesn't work in all cases
Submitted: 2002-09-29 08:22 UTC Modified: 2002-09-30 04:21 UTC
From: dirks dot plaza at hccnet dot nl Assigned:
Status: Not a bug Package: Directory function related
PHP Version: 4.2.0 OS: Windows 2000
Private report: No CVE-ID: None
 [2002-09-29 08:22 UTC] dirks dot plaza at hccnet dot nl
This script works OK:
if ($handle = @opendir('.')) {
   while (false !== ($file = readdir($handle))) {  
           if (is_dir($file)) { 
		   echo "Is directory $file <BR>"; 
		   else Print "Is file $file <BR>";
When I replace "." with i.e. "C:\webpages\test" (this is the directory where I run the script from) it also works fine.
But when I try the read a directory which is not in the same directory as the script i.e. "C:\webpages" than it displays that there are only files. So reading a directory lower or higher that the direcory where you are running a script from gives a wrong output.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-29 14:36 UTC]
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.
 [2002-09-30 04:21 UTC]
Sorry, but the bug system is not the appropriate forum for asking
support questions. 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

Thank you for your interest in PHP.

teh filename returned by readdir() is 
always relative to the opened directory
you have to concatenate dir- and filename
to get the complete path

  $dir = 'C:\Webpages\';
  if ($handle = @opendir($dir)) {
   while (false !== ($file = readdir($handle))) {  
           if (is_dir($dir.$file)) { 

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 25 21:01:29 2024 UTC