开发者

Convert URL to file system path

开发者 https://www.devze.com 2023-02-16 13:43 出处:网络
Is there a way to convert a web URL in to the absolute file system path (independent from OS)? For example: I have an URL /images/test.jpg (http://www.example.com/images/test.jpg) and I need to get:

Is there a way to convert a web URL in to the absolute file system path (independent from OS)?

For example: I have an URL /images/test.jpg (http://www.example.com/images/test.jpg) and I need to get:

  • `c:\path\to\webroot\images\test.jpg`` on Windows,
  • /var/path/to/webroot/images/test.jpg on Linu开发者_JAVA技巧x.

Any way to do this in PHP?


$str = "/images/test.jpg";
$str = realpath("." . $str);


This will give you /images/test.jpg:

$path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $path)

Where $_SERVER['DOCUMENT_ROOT'] gives you the document root directory under which the current script is executing.


It sounds like you want the realpath function.

0

精彩评论

暂无评论...
验证码 换一张
取 消