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';
精彩评论