function myrealpath($path, $check_file_exsits = true) {
$_DS = DIRECTORY_SEPARATOR;
$path = str_replace(
array("/", "\\"),
array($_DS, $_DS),
$path
);
$cwd = getcwd();
$arr = explode($_DS, $cwd);
$len = count($arr);
$arrAdd = explode($_DS, $path);
if (isset($arrAdd[0])) {
if ($_DS == '/') {
if (strpos($arrAdd[0], '/') !== false) {
$arr = array();
$len = 0;
}
} else {
if (strpos($arrAdd[0], ':') !== false) {
$arr = array();
$len = 0;
}
}
}
foreach($arrAdd as $part) {
if (strpos($part, '..') !== false) {
if ($len - 1 == 0) continue;
unset($arr[--$len]);
} elseif ($part == '.') {
} elseif (!empty($part)) {
$arr[$len++] = $part;
}
}
$full = implode($_DS, $arr);
if (file_exists($full) && $check_file_exsits) return $full;
elseif (!$check_file_exsits) return $full;
else return "";
}
Title:
How to write realpath function
Description:
function myrealpath($path, $check_file_exsits = true) { $_DS = DIRECTORY_SEPARATOR; $path = str_replace( array("/"...
...
Rating:
4