declaring directories as constants

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

declaring directories as constants

Post 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
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post 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
Post Reply