WAMP showing absolute path when echoing dirname(__FILE__)

本秂侑毒 提交于 2019-12-13 06:02:30

问题


I did this:

echo dirname(____FILE____) 

and it keeps showing as full absolute path as

C:/Program Files (x86)/VertrigoServ/www/dir/file.php

Why is that? I expect it to show

dir/file.php

I am using WAMP which is Apache on Windows.

BTW, calling $_SERVER['DOCUMENT_ROOT'] does the same thing - it shows full path.


回答1:


Try:

$webPath = str_replace($_SERVER['DOCUMENT_ROOT'], '', str_replace('\\', '/', __FILE__));

It'll take the absolute path to the file and remove the document root portion of it which should leave you with the path and file absolute from the document root.




回答2:


Although you don't state, if you're using wordpress I solved this issue by using:

file(bloginfo('home_url').'<path-to-file-without-leading-slash>')


来源:https://stackoverflow.com/questions/14823495/wamp-showing-absolute-path-when-echoing-dirname-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!