php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24171 is_dir() always returns false on non-relative base directories
Submitted: 2003-06-13 07:14 UTC Modified: 2003-06-13 07:24 UTC
From: php at webfreezer dot com Assigned:
Status: Not a bug Package: Directory function related
PHP Version: 4.3.2 OS: Windows XP
Private report: No CVE-ID: None
 [2003-06-13 07:14 UTC] php at webfreezer dot com
Description:
------------
Hi,

this bug has been described before however everyone seemed to make a mistake in the report.

Create this directory/file structure in the root of drive C:

- testDir
  -- Directory01
  -- Directory02
  -- Directory03
  -- file01.txt
  -- file02.txt
  -- file03.txt

Then start the script below.
The BUG occurs when using a non-relative directory, i.e. an ABSOULTE path.

The documentation states "Returns TRUE if the filename exists and is a directory. If filename is a relative filename, it will be checked relative to the current working directory."

It seems that a check is only performed in the current directory. If you uncomment the chdir line everything works fine!

Please fix this reproducible bug!
(Apache 1.3.27, PHP 4.3.2)


Reproduce code:
---------------
$baseDir="c:/testDir";
function parseDir($baseDir)
{
	$handle=@opendir($baseDir); 
	if($handle)
	{
		while ($file = readdir ($handle))
		{
		    if (is_dir($file))
			{
				echo $file." is a directory!<br>";
		    } else {
				echo $file." is NOT a directory!<br>";
			}
		}
		@closedir($handle);
	}
}
//chdir("c:/testDir");
parseDir("c:/testDir");

Expected result:
----------------
. is a directory!
.. is a directory!
Directory01 is a directory!
Directory02 is a directory!
Directory03 is a directory!
file01.txt is NOT a directory!
file02.txt is NOT a directory!
file03.txt is NOT a directory!


Actual result:
--------------
. is a directory!
.. is a directory!
Directory01 is NOT a directory!
Directory02 is NOT a directory!
Directory03 is NOT a directory!
file01.txt is NOT a directory!
file02.txt is NOT a directory!
file03.txt is NOT a directory!


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-13 07:17 UTC] wez@php.net
while ($file = readdir ($handle)) {
    if (is_dir($file))

This looks bogus... shouldn't you be testing:
is_dir($baseDir . DIRECTORY_SEPARATOR . $file)
instead?

 [2003-06-13 07:24 UTC] sniper@php.net
It's just broken script. Not a bug.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 02:01:30 2024 UTC