从站点中的任何位置指向目录的过程


Which procedure to point to a directory from everywhere in the site

如果我应该从网站的任何地方指向一个目录,哪一个是最好的过程?

$folder = "http://www.mysite.com/something/foldertopoint"

$folder = "/WEB/mysite/htdocs/something/foldertopoint"

为什么不使用类似__DIR__的东西呢?它是一个神奇的常数。如果你在配置文件中定义了一个路径

配置文件路径:/var/www/include/config.php

里面有

define('_INC_', __DIR__);

无论您在哪里使用常量_INC_,都将始终指向/var/www/include

所以如果你在:/var/www/some/crazy/path/of/nonsense.php

你可以简单地使用

include(_INC_."/myinclude.php");

包括/var/www/include/myinclude.php

在站点范围内尝试包含folers/files时可以节省时间。

取决于。若要链接到目录中的一个文件,请使用第一个文件。如果要对脚本中目录内的文件执行文件操作,则需要使用第二个操作。

我更喜欢$folder = "/WEB/mysite/htdocs/something/foldertopoint"

您的代码变得可重用,因为它不绑定到特定的域。