Page 1 of 1

declaring directories as constants

Posted: Thu Jan 18, 2007 2:09 pm
by sh33p1985
is there anyway to explicitly declare the path to a directory as a constant which can be used to easily point to it instead of using ../../ until you reach the root dir.

echo "<img src=" . $image_dir . "image.jpg/>" or something...

thanks

Posted: Thu Jan 18, 2007 2:17 pm
by aaronhall

Code: Select all

<?php
define('ROOT_DIRECTORY', '/path/to/public/dir/');

echo '<a href="' . ROOT_DIRECTORY . 'subdir/file.php">file</a>';
?>
Constants are globals, so you won't have to worry about using them in different scopes