Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- Test opendir() function : usage variations - different relative paths --SKIPIF-- ..

Decoded Output download

--TEST--
Test opendir() function : usage variations - different relative paths
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') {
  die("skip Valid only on Windows");
}
?>
--FILE--
<?php
/*
 * Test opendir() with different relative paths as $path argument
 */

echo "*** Testing opendir() : usage variation ***
";

$base_dir_path = __DIR__ . '/opendir_variation4-win32-mb';
@mkdir($base_dir_path);

$level_one_dir_name = "level_one";
$level_one_dir_path = "$base_dir_path/$level_one_dir_name";

$level_two_dir_name = "level_two";
$level_two_dir_path = "$base_dir_path/$level_one_dir_name/$level_two_dir_name";

// create directories
mkdir($level_one_dir_path);
mkdir($level_two_dir_path);

echo "
-- \$path = './level_one': --
";
var_dump(chdir($base_dir_path));
var_dump($dh = opendir("./$level_one_dir_name"));
clean_dh($dh);

echo "
-- \$path = 'level_one/level_two': --
";
var_dump(chdir($base_dir_path));
var_dump($dh = opendir("$level_one_dir_name/$level_two_dir_name"));
clean_dh($dh);

echo "
-- \$path = '..': --
";
var_dump($dh = opendir('..'));
clean_dh($dh);

echo "
-- \$path = 'level_two', '.': --
";
var_dump(chdir($level_two_dir_path));
var_dump($dh = opendir('.'));
clean_dh($dh);

echo "
-- \$path = '../': --
";
var_dump($dh = opendir('../'));
clean_dh($dh);

echo "
-- \$path = './': --
";
var_dump(chdir($level_two_dir_path));
var_dump($dh = opendir('./'));
clean_dh($dh);

echo "
-- \$path = '../../'level_one': --
";
var_dump(chdir($level_two_dir_path));
var_dump($dh = opendir("../../$level_one_dir_name"));
clean_dh($dh);

/*
 * function to remove directory handle before re-using variable name in test
 * and to ensure directory is not in use at CLEAN section so can me removed
 */
function clean_dh($dh){
    if (is_resource($dh)) {
        closedir($dh);
    }
    unset($dh);
}
?>
--CLEAN--
<?php
$base_dir_path = __DIR__ . '/opendir_variation4-win32-mb';
rmdir("$base_dir_path/level_one/level_two");
rmdir("$base_dir_path/level_one");
rmdir($base_dir_path);
?>
--EXPECTF--
*** Testing opendir() : usage variation ***

-- $path = './level_one': --
bool(true)
resource(%d) of type (stream)

-- $path = 'level_one/level_two': --
bool(true)
resource(%d) of type (stream)

-- $path = '..': --
resource(%d) of type (stream)

-- $path = 'level_two', '.': --
bool(true)
resource(%d) of type (stream)

-- $path = '../': --
resource(%d) of type (stream)

-- $path = './': --
bool(true)
resource(%d) of type (stream)

-- $path = '../../'level_one': --
bool(true)
resource(%d) of type (stream)

Did this file decode correctly?

Original Code

--TEST--
Test opendir() function : usage variations - different relative paths
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') {
  die("skip Valid only on Windows");
}
?>
--FILE--
<?php
/*
 * Test opendir() with different relative paths as $path argument
 */

echo "*** Testing opendir() : usage variation ***\n";

$base_dir_path = __DIR__ . '/opendir_variation4-win32-mb';
@mkdir($base_dir_path);

$level_one_dir_name = "level_one";
$level_one_dir_path = "$base_dir_path/$level_one_dir_name";

$level_two_dir_name = "level_two";
$level_two_dir_path = "$base_dir_path/$level_one_dir_name/$level_two_dir_name";

// create directories
mkdir($level_one_dir_path);
mkdir($level_two_dir_path);

echo "\n-- \$path = './level_one': --\n";
var_dump(chdir($base_dir_path));
var_dump($dh = opendir("./$level_one_dir_name"));
clean_dh($dh);

echo "\n-- \$path = 'level_one/level_two': --\n";
var_dump(chdir($base_dir_path));
var_dump($dh = opendir("$level_one_dir_name/$level_two_dir_name"));
clean_dh($dh);

echo "\n-- \$path = '..': --\n";
var_dump($dh = opendir('..'));
clean_dh($dh);

echo "\n-- \$path = 'level_two', '.': --\n";
var_dump(chdir($level_two_dir_path));
var_dump($dh = opendir('.'));
clean_dh($dh);

echo "\n-- \$path = '../': --\n";
var_dump($dh = opendir('../'));
clean_dh($dh);

echo "\n-- \$path = './': --\n";
var_dump(chdir($level_two_dir_path));
var_dump($dh = opendir('./'));
clean_dh($dh);

echo "\n-- \$path = '../../'level_one': --\n";
var_dump(chdir($level_two_dir_path));
var_dump($dh = opendir("../../$level_one_dir_name"));
clean_dh($dh);

/*
 * function to remove directory handle before re-using variable name in test
 * and to ensure directory is not in use at CLEAN section so can me removed
 */
function clean_dh($dh){
    if (is_resource($dh)) {
        closedir($dh);
    }
    unset($dh);
}
?>
--CLEAN--
<?php
$base_dir_path = __DIR__ . '/opendir_variation4-win32-mb';
rmdir("$base_dir_path/level_one/level_two");
rmdir("$base_dir_path/level_one");
rmdir($base_dir_path);
?>
--EXPECTF--
*** Testing opendir() : usage variation ***

-- $path = './level_one': --
bool(true)
resource(%d) of type (stream)

-- $path = 'level_one/level_two': --
bool(true)
resource(%d) of type (stream)

-- $path = '..': --
resource(%d) of type (stream)

-- $path = 'level_two', '.': --
bool(true)
resource(%d) of type (stream)

-- $path = '../': --
resource(%d) of type (stream)

-- $path = './': --
bool(true)
resource(%d) of type (stream)

-- $path = '../../'level_one': --
bool(true)
resource(%d) of type (stream)

Function Calls

None

Variables

None

Stats

MD5 c1990c9603d83e6d38bb45aaf96b59e8
Eval Count 0
Decode Time 93 ms