Ibrahim Azhar Armar Ibrahim Azhar Armar - 1 month ago 7
PHP Question

Path constant in PHP

I have different classes and a configuration file in my PHP Application. The classes sits inside a single directory. My application structure is as follows

/ApplicationName
/administrator
adminFiles.php
someMoreAdmingFiles.php
anotherAdminFiles.php
/resources
/config
config.php
/library
/class
class.user.php
class.acl.php
/models
/logs
/templates
/contents
/uploads
/css
/img
/css


i would like to create path CONSTANTS in config.php, now i used the following code to create a path constant for class.user.php

define('USERCLASS_PATH',$_SERVER['DOCUMENT_ROOT'].'/ApplicationName/administrator/resources/library/class/class.user.php');


Above CONSTANT generates the following string.

/Applications/MAMP/htdocs/ApplicationName/administrator/resources/library/class/class.user.php


is there any better way for achieving this?

Answer

I usually use something in the lines of:

define("PATH_ROOT", realpath(dirname(__FILE__)));
Comments