|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31377 is_dir function
Submitted: 2005-01-02 00:18 UTC Modified: 2005-01-11 09:49 UTC
From: intro at intro dot one dot pl Assigned:
Status: Not a bug Package: Directory function related
PHP Version: 5CVS-2005-01-02 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
41 + 49 = ?
Subscribe to this entry?

 [2005-01-02 00:18 UTC] intro at intro dot one dot pl
For example i have 4 folders in /home directory on unix platform (a,b,c,d) and php5. The script:
I have strange thing that function is_dir not always shows every dirs as it is dir. In my example script is_dir returned only "c" as dir and the rest (a,b,d) as file.

Reproduce code:
foreach ($files as $file)
	if (is_dir($file))
		echo "dir: $file";

Expected result:
dir: a dir: b dir: c dir: d

Actual result:
dir: c


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-02 07:45 UTC]
Please try using this CVS snapshot:
For Windows:

Also, add 'var_dump($files);' after the scandir() line and check the output. (permissions..?)

 [2005-01-02 12:14 UTC] intro at intro dot one dot pl
by "var_dump($files);" after scandir everything are listing good. Permissions etc. is ok and files and folders are readable. I checked some others dirs and sometimes files is showing as dir (for example .directory and others hidden files).
"Please try using this CVS snapshot:" still doesn't work correctly.
 [2005-01-02 19:00 UTC] intro at intro dot one dot pl
Hmmmm i've done something else. Function filetype. And after use filetype on some folder i have many warnings that "Lstat failed for file". And the same way i think works "is_dir". Only a few files and folders are with no this warning and is showing as dir or file etc. The same is on other functions as is_file etc. My last code in tests:


$directorytoread = "/home"
$listdirindir = array();

// var_dump($files);
// all files are listing which is in folder /home

foreach ($files as $file)
  if ( filetype($file) == "dir" )
  echo "File \"$file\" is dir and ";
  if (is_dir($file))
    echo "dir \"$file\" added<br/>";


...and my examples result is:

many of warnings +
File "." is dir and dir "." added
File ".." is dir and dir ".." added
+ many of warnings +
File "c" is dir and dir "c" added
+ many of warnings +
Array ( [0] => . [1] => .. [2] => c )
 [2005-01-10 21:34 UTC]
Try is_dir($directorytoread.'/'.$file) first.
 [2005-01-10 22:12 UTC] intro at intro dot one dot pl
"Try is_dir($directorytoread.'/'.$file) first."

... yes it is true, i could try it earlier :-). This works correctly, but with one thing: does "is_dir" function schould display a symbolic links (but only to some directory) as dir ?? Doesn't do it "is_link" function (where it shows symbolic links to directory too) ??
when function filetype works in any way correctly.

 [2005-01-11 09:49 UTC]
>does "is_dir" function schould display a symbolic
>links (but only to some directory) as dir ??
is_dir() resolves symlinks.

No bug, just a user mistake -> bogus.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 04:01:28 2024 UTC