将文档根目录定义为ROOT

编程入门 行业动态 更新时间:2024-10-26 05:17:12
本文介绍了将文档根目录定义为ROOT_PATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用一些常量来定义要构建的网站上特定目录的路径,例如:

I use some constants to define paths to specific directories on a website that I'm building, like this:

define("ROOT_PATH", "website/"); define("IMAGES_DIR", ROOT_PATH . "images/");

,我通常这样使用它们:

and I usually use them like this:

echo "<img src='" . IMAGES_DIR . "some_image.jpg' />";

现在我想知道之间是否有任何区别

now I want to know if there is any difference between

define("ROOT_PATH", "website/");

define("ROOT_PATH", "/home/username/public_html/");

我应该使用哪一个?为什么?

and which one of them should I use? And why?

推荐答案

您不能真正使用以下内容:

You can't really use the following:

define("ROOT_PATH", "/home/username/public_html/");

因为它将尝试加载

website/home/username/public_html/image.png

您不想要的。

使用

define("ROOT_PATH", "website/");

将尝试获取

website/image.png

这是什么你想要的。

更多推荐

将文档根目录定义为ROOT

本文发布于:2023-08-02 11:49:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1277563.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:根目录   定义   文档   ROOT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!