Monday, July 25, 2011

How to get the include once -php anywhere?

you can now get your script, config or class included anywhere and get the correct path using dirname and __FILE__
Here's an example:

from here you can get the absolute path of your file like the one I've shown will result in:
/home/user/public_html/inc/class/class.php and the script resides in /home/user/public_html/some/down/subdir/subdir/index.php that require the class to be included.

It will recrusively go up one level path and get the absolute path of the class name to be include. This is useful when you have lots of include that needed and want it to be accessible through out your main apps.