Hi all :D My file structure is as follow:
/site
/public_html
/1
/2
/3
read.php
/file
file.doc
For security reasons, I moved my docs outside public_html folder.
Inside read.php, I am accessing file.doc via code "../../../../file/file.doc"
Are there other methods (shortcuts?) to access the doc? I call on a lot of files from many locations. This code is too long and easy to lose track on how many ../ I need.
If your virtual host is rooted on /site/public_html you can shorten it a little by using $_SERVER['DOCUMENT_ROOT']; this should work for all scripts underneath the document root in the same manner.
$file = $_SERVER['DOCUMENT_ROOT']. '/../file/file.doc';
You can set a ROOT constant that points to the root:
# on read.php
define('ROOT', dirname(dirname(dirname(dirname(dirname(__FILE__))))).DIRECTORY_SEPARATOR;
and then just call:
# anywhere else
include ROOT.'file/file.doc';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With