新手:网站的根目录 [英] newbie: website's root directory
问题描述
您好,
我正在学习PHP5。我需要在.php
代码中获取我的网站的根目录。我尝试了代码:
echo __DIR __,$ _SERVER [''DOCUMENT_ROOT''];
但显示:
__DIR __ / var / www / html
虽然my_website安装在用户的
目录中:/ home / robert / public_html / my_website。
我不喜欢不知道为什么以及如何获得根目录。
请帮忙。
谢谢!
Hello,
I am learning PHP5. I need to obtain my website''s root directory in .php
code. I tried the code:
echo __DIR__, $_SERVER[''DOCUMENT_ROOT''];
but it displays:
__DIR__/var/www/html
although my_website is installed in user''s
directory: /home/robert/public_html/my_website.
I don''t know why and how to obtain root directory.
Please help.
Thanks!
推荐答案
_SERVER [''DOCUMENT_ROOT''];
但显示:
__DIR __ / var / www / html
虽然my_website是安装在用户的
目录中:/ home / robert / public_html / my_website。
我不知道为什么以及如何获取根目录。
请帮忙。
谢谢!
_SERVER[''DOCUMENT_ROOT''];
but it displays:
__DIR__/var/www/html
although my_website is installed in user''s
directory: /home/robert/public_html/my_website.
I don''t know why and how to obtain root directory.
Please help.
Thanks!
Jivanmuktaescribió:
Jivanmukta escribió:
我正在学习PHP5。我需要在.php
代码中获取我的网站的根目录。我尝试了代码:
echo __DIR __,
I am learning PHP5. I need to obtain my website''s root directory in .php
code. I tried the code:
echo __DIR__,
_SERVER [''DOCUMENT_ROOT''];
但显示:
__DIR __ / var / www / html
虽然my_website安装在用户的
目录中:/ home / robert / public_html / my_website。
_SERVER[''DOCUMENT_ROOT''];
but it displays:
__DIR__/var/www/html
although my_website is installed in user''s
directory: /home/robert/public_html/my_website.
在PHP 5.3.0中添加了__DIR__常量,据我所知,
预计将在未来几个月内发布。
http:/ /es.php.net/manual/en/language...predefined.php
您的问题是您的ISP已经在这样的
DOCUMENT_ROOT值不可靠的方式。你需要自己计算
。你的站点根目录中的一个简单的dirname(__ FILE__)就可以了。
-
- http://alvaro.es - álvaroG。Vicario - 西班牙布尔戈斯
- Mi sitiosobreprogramaciónweb:< a rel =nofollowhref =http://bits.demogracia.comtarget =_ blank> http://bits.demogracia.com
- Mi web de humor al ba?oMaría: http://www.demogracia.com >
-
The __DIR__ constant was added in PHP 5.3.0, which as fas as I know is
expected to be released in the next months.
http://es.php.net/manual/en/language...predefined.php
Your problem is that your ISP has configured the web server in such a
way that the DOCUMENT_ROOT value is unreliable. You''ll need to calculate
it yourself. A simple dirname(__FILE__) in your site root will do the trick.
--
-- http://alvaro.es - álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al ba?o María: http://www.demogracia.com
--
这篇关于新手:网站的根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!