Edit report at http://bugs.php.net/bug.php?id=39198&edit=1

 ID:                 39198
 Comment by:         h_guillaume at hotmail dot com
 Reported by:        php dot spam at frogblender dot net
 Summary:            is_dir seem to have permission problems
 Status:             No Feedback
 Type:               Bug
 Package:            Directory function related
 Operating System:   Windows 2003
 PHP Version:        5.1.6
 Block user comment: N

 New Comment:

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;

    }

}


Previous Comments:
------------------------------------------------------------------------
[2008-07-08 07:39:46] phpbugs at mainskill dot com

Addition to my previous comment: This happens in safe mode only.

------------------------------------------------------------------------
[2008-07-08 07:22:55] 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 tony2...@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.

------------------------------------------------------------------------
[2007-06-04 22:12:57] 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)

------------------------------------------------------------------------
[2007-05-20 13:24:43] 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.

------------------------------------------------------------------------
[2006-11-17 01:00:00] 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".

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=39198


-- 
Edit this bug report at http://bugs.php.net/bug.php?id=39198&edit=1

Reply via email to