PHP code example to convert relative path to absolute path through realpath

不言
Release: 2023-04-03 17:20:01
Original
3156 people have browsed it

This article brings you a code example about PHP converting a relative path to an absolute path through realpath. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Relative path-> Absolute path:

 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); ?>
Copy after login

output:

0 /Users/Mch/eclipse-workspace/blog.zip
Copy after login

Just realpath here, why bother?

Recommended related articles:

How to store session in database and use it in PHP (with code)

How does PHP access URL? Summary of methods for accessing URLs in php (code)

The above is the detailed content of PHP code example to convert relative path to absolute path through realpath. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!