|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 15:00:01 2025 UTC |
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)<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.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; } }