新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
php怎么轉(zhuǎn)換成絕對(duì)路徑
本文操作環(huán)境:Windows7系統(tǒng)、php7.4版、DELL G3電腦

創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供寶應(yīng)網(wǎng)站建設(shè)、寶應(yīng)做網(wǎng)站、寶應(yīng)網(wǎng)站設(shè)計(jì)、寶應(yīng)網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、寶應(yīng)企業(yè)網(wǎng)站模板建站服務(wù),10余年寶應(yīng)做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
php 怎么轉(zhuǎn)換成絕對(duì)路徑?
PHP 相對(duì)路徑轉(zhuǎn)換為絕對(duì)路徑 realpath
* 相對(duì)路徑 -> 絕對(duì)路徑 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就可以了,為什么多此一舉?
* 絕對(duì)路徑 -> 相對(duì)路徑
= count($a) || $j >= count($b)) {
throw new Exception('$j out of range');
}
for ($i = $j; $i >= 0; $i--) {
if (strcmp($b[$i], $a[$i])!==0) {
return false;
}
}
return true;
};
// 找到a,b數(shù)組元素相同的下標(biāo)
while (array_pop($a)) {
$i = count($a)-1;
if (isset($b[$i])) {
if ($sliceEquals($a, $b, $i)) {
break;
}
}
array_push($d, "..");
}
// 從首個(gè)不同元素開始
for ($i+=1; $i < count($b); $i++) {
array_push($d, $b[$i]);
}
return ".".DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $d);
} 名稱欄目:php怎么轉(zhuǎn)換成絕對(duì)路徑
網(wǎng)頁(yè)路徑:http://fisionsoft.com.cn/article/dhsgeso.html


咨詢
建站咨詢
