You are using a browser which is not compatible with CSS (for more information, see Tara's tutorial). Because of this, it is possible that our website may not appear correctly in your browser. We apologise for the inconvenience, and recommend you upgrade your browser to one which is compatible with CSS. For more information, please visit our Browser Upgrade page.

4WebHelp

Scripts: PHP: Find your base directory

This script will output the path to your base directory (aka "Document Root"), which often needs to be used in Perl & PHP scripts.

<?php

###########################################################################
#                                                                         #
# Neither http://www.4webhelp.net/ nor its members accept any             #
# responsibility, either expressed or implied, for any damage caused by   #
# using this script or the misuse of this script.                         #
#                                                                         #
#                                                                         #
#                          INSTRUCTIONS                                   #
#                                                                         #
# 1) Copy this code to an editor such as Notepad and save it with a       #
# .php  extension.                                                        #
# 2) FTP this file to a folder on your site in ASCII mode                 #
# 3) Call up this file in your web browser to see your document root      #
#                                                                         #
###########################################################################

print ($_SERVER['DOCUMENT_ROOT']);

?>

<p>This script courtesy of <a href="http://www.4webhelp.net/">4WebHelp</a>.</p>
Comments
Name: RonEmail rdelrosario at ftsp dot ten dot fujitsu dot com
thank you for this! Really helped!
Name: MarkEmail none
Would it not be better just to use an info.php file for all this stuff, you not only get paths but all Apache info
Name: PaulaEmail none
My register globals are off, yet "echo getcwd()" works for me.
Name: fwdEmail none
echo getcwd();  

That prints the current working dir. and always works...
Name: ArkitektEmail ark at arkitekture dot com
PERFECT... exactly what I needed.  Was dealing with a host that had a file structure that I was totally unfamiliar with and the CMS program required the full path to root...

THANKS!
Name: Tim BEmail none
omg i cant beleave its that simple, ive been lookin for this exact thing for the past 15 hours and i couldnt find it in my php books or on php.net, cant beleave its as simple as "print ($_SERVER['DOCUMENT_ROOT']);" thank you for this
Name: thessoroEmail standby at ono dot com
<?php echo $_SERVER['DOCUMENT_ROOT']; ?> will always work from PHP 4.1.0 version. The script above depends on "register_globals" being "On" (in that case you'd better turn it Off)
register_globals is off by default since PHP 4.2.0 due to the potencial risk of variable poisoning.
Name: gabriellaEmail none
superb! a truly great little script!

Add a new comment

This page is © Copyright 2002-2008, 4WebHelp. It may not be reproduced without 4WebHelp's prior permission.