@ 2014-02-03T10:48:58Z <?php
function realPath2($path)
{
$isUnixPath = ((strlen($path) === 0) || ($path[0] !== '/'));
// Checks if path is relative.
if ((strpos($path, ':') === false) && ($isUnixPath === true)) {
$path = getcwd() . DIRECTORY_SEPARATOR . $path;
}
// Resolve path parts (single dot, double dot and double delimiters).
$path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
$parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
$absolutes = array();
foreach ($parts as $part) {
if (('.' === $part) || ('' === $part)) {
continue;
}
if ('..' === $part) {
array_pop($absolutes);
} else {
$absolutes[] = $part;
}
}
$path = implode(DIRECTORY_SEPARATOR, $absolutes);
// Resolve any symlinks.
if ((file_exists($path) === true) && (linkinfo($path) > 0)) {
$path = readlink($path);
}
if ($isUnixPath === false) {
$path = '/' . $path;
}
return $path;
}
echo realPath2('phar://test.phar/a/b/./.././v/../file.txt');
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.1.26 - 7.1.33 , 7.2.17 - 7.2.33 , 7.3.0 - 7.3.31 , 7.4.0 - 7.4.25 , 7.4.27 - 7.4.32 , 8.0.0 - 8.0.12 , 8.0.14 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Warning: file_exists(): open_basedir restriction in effect. File(phar:/test.phar/a/file.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/ra9YY on line 28
phar:/test.phar/a/file.txt Output for 4.3.0 - 4.3.11 , 4.4.0 - 4.4.9 , 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.8 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.7 , 7.3.32 - 7.3.33 , 7.4.26 , 7.4.33 , 8.0.13 phar:/test.phar/a/file.txt Output for 7.1.20 , 7.2.6 Warning: file_exists(): open_basedir restriction in effect. File(phar:/test.phar/a/file.txt) is not within the allowed path(s): (/tmp:/in) in /in/ra9YY on line 28
phar:/test.phar/a/file.txt preferences:dark mode live preview
212.89 ms | 402 KiB | 341 Q