ID:               39198
 Comment by:       legolas558 at users dot sourceforge dot net
 Reported By:      php dot spam at frogblender dot net
 Status:           No Feedback
 Bug Type:         Directory function related
 Operating System: Windows 2003
 PHP Version:      5.1.6
 New Comment:

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 ([EMAIL PROTECTED]($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.


Previous Comments:
------------------------------------------------------------------------

[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".

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

[2006-11-09 10:06:54] [EMAIL PROTECTED]

>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-09 09:58:45] 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-08 21:21:32] [EMAIL PROTECTED]

This script is no enough, as we don't have your directory structure.

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

[2006-11-03 19:58:57] php dot spam at frogblender dot net

You've already got the reproducing script in my original post.

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

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/39198

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

Reply via email to