WAMP显示呼应目录名称时,绝对路径(__ FILE__) [英] WAMP showing absolute path when echoing dirname(__FILE__)

查看:141
本文介绍了WAMP显示呼应目录名称时,绝对路径(__ FILE__)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样做:

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

我使用WAMP是Apache的Windows上。

I am using WAMP which is Apache on Windows.

顺便说一句,叫 $ _ SERVER ['DOCUMENT_ROOT'] 做同样的事情 - 它显示完整路径。

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

推荐答案

尝试:

$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.

这篇关于WAMP显示呼应目录名称时,绝对路径(__ FILE__)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆