开发者

How to correctly reference hosting root?

开发者 https://www.devze.com 2023-01-28 07:32 出处:网络
Say I have a \"test.db\" file under www.myhosting.com/data/test.db. I need to reference this file from www.myhosting.com/inc/functions.php

Say I have a "test.db" file under www.myhosting.com/data/test.db. I need to reference this file from www.myhosting.com/inc/functions.php

What would be the proper way to reference the file?

$filename = '../data/test.db';

is not appropiate because www.myhosting.com/index.php would try to g开发者_如何学Goo to a non existant parent dir ../data


Create (if you still doesn't have one) config.php file where you define absolute path to your root and include it in every your script. After that - use that constant to assemble path.

Ie:

$filename = ROOT_PATH . '/data/test.db';


First way:

$filename = $_SERVER['DOCUMENT_ROOT'] . '/data/test.db';

Second:

$filename = getcwd() . '../data/test.db';
0

精彩评论

暂无评论...
验证码 换一张
取 消