本篇文章给大家带来的内容是关于PHP通过 realpath将相对路径转换为绝对路径的代码实例,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
相对路径 -> 绝对路径:
relative path
$c_abs = realpath($ss_rel);
if ($c_abs === false) {
$i_rtn = -1;
} else {
$ss_rel = $c_abs;
$i_rtn = 0;
}
$lpc++;
} // while (count($sv_path)>0)
// normal ending
if (0===$i_rtn) {
$out_abs = $ss_rel; // set converted path
}
return $i_rtn;
}
// test
$inDir = "/Users/Mch/Code/php/Directory";
is_dir($inDir) || mkdir($inDir, 0777, true);
$wd = __DIR__;
chdir($inDir);
$out = "";
echo sub_rel2abs("../../../eclipse-workspace/blog.zip", $out).PHP_EOL;
echo $out.PHP_EOL;
chdir($wd);
@rmdir($inDir);
?>output:
0 /Users/Mch/eclipse-workspace/blog.zip
这里直接realpath就可以了,为什么多此一举?
相关文章推荐:
立即学习“PHP免费学习笔记(深入)”;











