定义当配置文件放置在根文件夹外时根文件夹出错


define root folder going wrong when config file placed out of root folder

在config.php中,我将根文件夹定义为

define('ROOT_DIR', str_replace('''', '/', realpath(dirname(__FILE__) . '../')) . '/');

c:/xampp/根/myWebsite/

为了安全起见,我把config.php文件移出根目录,放在config文件夹下。

问题是,现在的root_dir是之前的

c:/xampp/根/myWebsite

c:/xampp/根/config/

如何保持config.php现在的位置(在将其从根目录移开之后),并使根目录显示为

c:/xampp/根/myWebsite/

检查是否有效:

define('ROOT_DIR',$_SERVER['DOCUMENT_ROOT'] . "/myWebsite/");

经过多次尝试,我终于使用这行代码来定义我的ROOT目录

定义("ROOT_DIR"。大小写不敏感 (''', '/', realpath(目录名(文件)。"/. ./"))。'/public_html/', false);

似乎在一个实时服务器上工作得很好。