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 chdir() function : usage variations - relative paths --SKIPIF-- <?php if (su..

Decoded Output download

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

echo "*** Testing chdir() : usage variations ***
";

$base_dir_path = __DIR__ . '/chdir_variation2-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 "
-- \$directory = './level_one': --
";
var_dump(chdir($base_dir_path));
var_dump(chdir("./$level_one_dir_name"));
var_dump(getcwd());

echo "
-- \$directory = 'level_one/level_two': --
";
var_dump(chdir($base_dir_path));
var_dump(chdir("$level_one_dir_name/$level_two_dir_name"));
var_dump(getcwd());

echo "
-- \$directory = '..': --
";
var_dump(chdir('..'));
var_dump(getcwd());

echo "
-- \$directory = 'level_two', '.': --
";
var_dump(chdir($level_two_dir_path));
var_dump(chdir('.'));
var_dump(getcwd());

echo "
-- \$directory = '../': --
";
var_dump(chdir('../'));
var_dump(getcwd());

echo "
-- \$directory = './': --
";
var_dump(chdir($level_two_dir_path));
var_dump(chdir('./'));
var_dump(getcwd());

echo "
-- \$directory = '../../'level_one': --
";
var_dump(chdir($level_two_dir_path));
var_dump(chdir("../../$level_one_dir_name"));
var_dump(getcwd());
?>
--CLEAN--
<?php
$base_dir_path = __DIR__ . '/chdir_variation2-win32-mb';
chdir(__DIR__); /* not that PWD is accidentialy one of the dirs to be deleted. */
rmdir("$base_dir_path/level_one/level_two");
rmdir("$base_dir_path/level_one");
rmdir($base_dir_path);
?>
--EXPECTF--
*** Testing chdir() : usage variations ***

-- $directory = './level_one': --
bool(true)
bool(true)
string(%d) "%slevel_one"

-- $directory = 'level_one/level_two': --
bool(true)
bool(true)
string(%d) "%slevel_one%elevel_two"

-- $directory = '..': --
bool(true)
string(%d) "%slevel_one"

-- $directory = 'level_two', '.': --
bool(true)
bool(true)
string(%d) "%slevel_one%elevel_two"

-- $directory = '../': --
bool(true)
string(%d) "%slevel_one"

-- $directory = './': --
bool(true)
bool(true)
string(%d) "%slevel_one%elevel_two"

-- $directory = '../../'level_one': --
bool(true)
bool(true)
string(%d) "%slevel_one"

Did this file decode correctly?

Original Code

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

echo "*** Testing chdir() : usage variations ***\n";

$base_dir_path = __DIR__ . '/chdir_variation2-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-- \$directory = './level_one': --\n";
var_dump(chdir($base_dir_path));
var_dump(chdir("./$level_one_dir_name"));
var_dump(getcwd());

echo "\n-- \$directory = 'level_one/level_two': --\n";
var_dump(chdir($base_dir_path));
var_dump(chdir("$level_one_dir_name/$level_two_dir_name"));
var_dump(getcwd());

echo "\n-- \$directory = '..': --\n";
var_dump(chdir('..'));
var_dump(getcwd());

echo "\n-- \$directory = 'level_two', '.': --\n";
var_dump(chdir($level_two_dir_path));
var_dump(chdir('.'));
var_dump(getcwd());

echo "\n-- \$directory = '../': --\n";
var_dump(chdir('../'));
var_dump(getcwd());

echo "\n-- \$directory = './': --\n";
var_dump(chdir($level_two_dir_path));
var_dump(chdir('./'));
var_dump(getcwd());

echo "\n-- \$directory = '../../'level_one': --\n";
var_dump(chdir($level_two_dir_path));
var_dump(chdir("../../$level_one_dir_name"));
var_dump(getcwd());
?>
--CLEAN--
<?php
$base_dir_path = __DIR__ . '/chdir_variation2-win32-mb';
chdir(__DIR__); /* not that PWD is accidentialy one of the dirs to be deleted. */
rmdir("$base_dir_path/level_one/level_two");
rmdir("$base_dir_path/level_one");
rmdir($base_dir_path);
?>
--EXPECTF--
*** Testing chdir() : usage variations ***

-- $directory = './level_one': --
bool(true)
bool(true)
string(%d) "%slevel_one"

-- $directory = 'level_one/level_two': --
bool(true)
bool(true)
string(%d) "%slevel_one%elevel_two"

-- $directory = '..': --
bool(true)
string(%d) "%slevel_one"

-- $directory = 'level_two', '.': --
bool(true)
bool(true)
string(%d) "%slevel_one%elevel_two"

-- $directory = '../': --
bool(true)
string(%d) "%slevel_one"

-- $directory = './': --
bool(true)
bool(true)
string(%d) "%slevel_one%elevel_two"

-- $directory = '../../'level_one': --
bool(true)
bool(true)
string(%d) "%slevel_one"

Function Calls

None

Variables

None

Stats

MD5 3af3f78491383de418e5d123f28ea475
Eval Count 0
Decode Time 104 ms