php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39198 is_dir seem to have permission problems
Submitted: 2006-10-19 14:00 UTC Modified: 2006-11-17 01:00 UTC
Votes:27
Avg. Score:4.4 ± 1.0
Reproduced:21 of 21 (100.0%)
Same Version:8 (38.1%)
Same OS:8 (38.1%)
From: php dot spam at frogblender dot net Assigned:
Status: No Feedback Package: Directory function related
PHP Version: 5.1.6 OS: Windows 2003
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php dot spam at frogblender dot net
New email:
PHP Version: OS:

 

 [2006-10-19 14:00 UTC] php dot spam at frogblender dot net
Description:
------------
If you have a directory where Everyone has "Full Control" rights you would expect is_dir to return true but it doesn't.

This bug has existed since 5.0.0 and I've had this problem on at least three servers during the past year.

I'm lying about my PHP version (it's really 5.1.4) but I've checked the change log.

realpath() seem to exhibit the proper behavior.

Reproduce code:
---------------
<?php
print("<pre>");
error_reporting(E_ALL);
#clearstatcache();

$paths = array(
	"C:\\",
	"C:\\Windows",
	"C:\\Windows\\Temp",
	"C:\\Windows\\Temp\\RP_Compile",
	"C:\\Windows\\Temp\\DoesNotExist",
	"C:\\Windows\\Temp\\RP_Compile\\Subdir",
);

print("\nis_dir()\n");
foreach($paths as $path)
	print(is_dir($path) . " \t$path\n");

print("\nrealpath()\n");
foreach($paths as $path)
	print(!(realpath($path) === FALSE) . " \t$path\n");

print("\nstat()\n");
foreach($paths as $path)
	print(!(stat($path) === FALSE) . " \t$path\n");

print("</pre>");
?>


Expected result:
----------------
is_dir()
1 	C:\
1 	C:\Windows
1 	C:\Windows\Temp
1 	C:\Windows\Temp\RP_Compile
 	C:\Windows\Temp\DoesNotExist
1 	C:\Windows\Temp\RP_Compile\Subdir

realpath()
1 	C:\
1 	C:\Windows
1 	C:\Windows\Temp
1 	C:\Windows\Temp\RP_Compile
 	C:\Windows\Temp\DoesNotExist
1 	C:\Windows\Temp\RP_Compile\Subdir


Actual result:
--------------
Notice the different result for "C:\Windows\Temp\RP_Compile"

is_dir()
1 	C:\
1 	C:\Windows
1 	C:\Windows\Temp
 	C:\Windows\Temp\RP_Compile
 	C:\Windows\Temp\DoesNotExist
1 	C:\Windows\Temp\RP_Compile\Subdir

realpath()
1 	C:\
1 	C:\Windows
1 	C:\Windows\Temp
1 	C:\Windows\Temp\RP_Compile
 	C:\Windows\Temp\DoesNotExist
1 	C:\Windows\Temp\RP_Compile\Subdir


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-19 14:04 UTC] tony2001@php.net
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


 [2006-10-19 15:38 UTC] php dot spam at frogblender dot net
Sorry, but I don't care whether this bug will be fixed or not.

The server is not mine to mess with so I can't install another PHP version.
 [2006-10-19 16:09 UTC] tony2001@php.net
Sorry, we can't go back to the past and fix it on your server.
 [2006-10-23 12:27 UTC] php dot spam at frogblender dot net
There's nothing wrong with our server, thank you.

I happened to remember an old Windows 2000 server I could test this on. The bug was reproducible with PHP 5.0 and 5.2 RC6, no surprise there. Was using IIS with default user, php5isapi.dll, unmodified php.ini

Tony2001, perhaps you shouldn't be managing bugs related to Windows if you don't have the equipment to verify them.
 [2006-10-23 12:43 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2006-10-31 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2006-11-03 19:58 UTC] php dot spam at frogblender dot net
You've already got the reproducing script in my original post.
 [2006-11-08 21:21 UTC] tony2001@php.net
This script is no enough, as we don't have your directory structure.
 [2006-11-09 09:58 UTC] php dot spam at frogblender dot net
I don't have your directory structure either so I can't adapt the script for your machine.

The Temp directory will be there in a standard installation of Windows. You then search and replace in my script to adapt to your environment. Finally you create one directory RP_Compile and give Everyone full rights on that directory.

It shouldn't take more than five minutes for anyone who knows how to log in to Windows.
 [2006-11-09 10:06 UTC] tony2001@php.net
>I don't have your directory structure either so I can't
> adapt the script for your machine.

Surely you can. 
Just create all the required directories in the script itself, don't left us guessing which directories exist and which don't.
 [2006-11-17 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2007-05-20 13:24 UTC] legolas558 at users dot sourceforge dot net
The problem seems affecting only the temporary directory's subdirectories; please fix this bug because it is causing a lot of weird effects on scripts which verify paths existance and eventually create them.

I am using PHP 5.2.0 and running this script:
<?php
// bug #39198 testcase, see http://bugs.php.net/bug.php?id=39198
// @author legolas558

if ( !function_exists('sys_get_temp_dir') ) {
    // Based on http://www.phpit.net/
    // article/creating-zip-tar-archives-dynamically-php/2/
    function sys_get_temp_dir() {
        // Try to get from environment variable
        if ( !empty($_ENV['TMP']) )
            return realpath( $_ENV['TMP'] );
        else if ( !empty($_ENV['TMPDIR']) )
            return realpath( $_ENV['TMPDIR'] );
        else if ( !empty($_ENV['TEMP']) )
            return realpath( $_ENV['TEMP'] );
        // Detect by creating a temporary file
        else {
            // Try to use system's temporary directory
            // as random name shouldn't exist
            $temp_file = tempnam( md5(uniqid(rand(), TRUE)), '' );
            if ($temp_file) {
                $d_temp = realpath( dirname($temp_file) );
                unlink( $temp_file );
                return $d_temp;
            } else
                return FALSE;
        }
    }
}

$d_temp= sys_get_temp_dir();

if ($d_temp===false)
	die('Cannot retrieve temporary path');

$d_temp = str_replace('\\','/', $d_temp);

if ($d_temp[strlen($d_temp)-1]!='/')
	$d_temp .= '/';

// now $d_temp contains a correctly formatted path e.g. C:/Windows/TEMP/

$my_temp_subdir = $d_temp.'39198_exists';

if (@rmdir($my_temp_subdir))
	echo "I just removed a previous <strong>$my_temp_subdir</strong> folder, now ";

// create a directory under the temporary path
if (!mkdir($my_temp_subdir))
	die("I could not create <strong>$my_temp_subdir</strong>");
else
	echo "<strong>$my_temp_subdir</strong> was created ";

// use here temp_is_dir() to see how the script should work instead
$b = is_dir($my_temp_subdir);

if (!$b)
	echo "but the folder is not a dir (through is_dir())!";
else
	echo "and is recognized as a dir (through is_dir())";

// workaround function
function temp_is_dir($dir) {
	// check directory existance under temp folder (tested on Windows)
	// see bug #31918 http://bugs.php.net/bug.php?id=39198
	// by legolas558
	if (!@mkdir($dir))
		return true;
	rmdir($dir);
	return false;
}

?>
I get this talkative output:
[code]
C:/WINDOWS/Temp/39198_exists was created but the folder is not a dir (through is_dir())!
[/code]

But the correct talkative output would be instead:
[code]
C:/WINDOWS/Temp/39198_exists was created and is recognized as a dir (through is_dir())
[/code]

Note that using the workaround function "temp_is_dir()" in place of "is_dir()" the correct output would be returned instead. Please ask me more if necessary.
 [2007-06-04 22:12 UTC] sweston at lyon dot edu
I having the same problem.

OS: FreeBSD 6.2
PHP: 5.1.2
Server: Apache 2.2

Mount a windows share.
Run the following on the windows share:

$d = dir("Path/to/windows/share");
while (false !== ($entry = $d->read())) {
   echo "Entry: $entry<br>\n";
   var_dump(is_dir($entry));
   echo "<br>";
}

All sub-directories on the windows share return:

Entry: Sub_Dir_1
bool(false)
Entry: Sub_Dir_2
bool(false)
 [2008-07-08 07:22 UTC] phpbugs at mainskill dot com
<code>
// this script runs under user www-data
// Apache/2.2.3 (Debian) 
//      PHP/5.2.0-8+etch11 
...
echo "\$dirName is $dirName<br>\n";

$FullDirname = realpath( $dirName );
echo "\$FullDirname is $FullDirname<br>\n";

if (!is_dir( $FullDirname )) {
      // as the directory is there this should never
      // be displayed!
      echo "$FullDirname is not a directory<br>\n";
}
</code>

output:
$dirName is mswbt_A6565897X3B91B
$FullDirname is /var/www/V3.46-pre03/source/mswbt_A6565897X3B91B
/var/www/V3.46-pre03/source/mswbt_A6565897X3B91B is not a directory


this clearly shows that the directory is there
$ ls -als /var/www/V3.46-pre03/source/
insgesamt 16
4 drwxrwsrwx  4 www-data www-data 4096 2008-07-07 16:17 .
4 drwxr-xr-x 14 root     root     4096 2008-07-07 16:19 ..
4 drwxr-sr-x  5 www-data www-data 4096 2008-07-07 16:17 mswbt_A6565897X3B91B


Msg to tony2001@php.net:
Please do not try to run this code on your machine. You will most probably *not* have this directory structure and the is_dir() function call would succeed on your machine as returning FALSE would be correct then!

I hope this can help a bit to solve the problem.
 [2008-07-08 07:39 UTC] phpbugs at mainskill dot com
Addition to my previous comment: This happens in safe mode only.
 [2010-10-26 00:49 UTC] h_guillaume at hotmail dot com
I encoutered the same error, my problem was not a bug, but a bad relative path error inside the script function is_dir(), maybe it can help someone having the same problem.

I am using Linux.

With the folowing structure
/var/www/vhosts/test.com/httpdocs/images/items_images/file1.jpg
/var/www/vhosts/test.com/httpdocs/images/items_images/temp

/* The folder "temp" will show as directory with the following script: */
$full_path = "/var/www/vhosts/test.com/httpdocs/images/items_images";
if ($handle = opendir("$full_path")) {
    while (false !== ($file = readdir($handle))) {
        if(is_dir($full_path."/".$file)) continue;
        else echo $file;
    }
}

/* The folder "temp" will show as a file with the following script: */
$full_path = "/var/www/vhosts/test.com/httpdocs/images/items_images";
if ($handle = opendir("$full_path")) {
    while (false !== ($file = readdir($handle))) {
        if(is_dir($file)) continue;
        else echo $file;
    }
}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Oct 12 13:01:27 2024 UTC