Sometimes when I look at other peoples PHP code they have something like this in there:
what is DIR?
The only one I know about is FILE, it is the full name and path of the current file.
The only way I can see that they get DIR is by defining it like this
define('__DIR__', pathinfo(__FILE__, PATHINFO_DIRNAME));
Which will give you the absolute path to the current file.
sorry yes i meant FILE
I dont quite get it - this refers to the filename of the PHP script or something else?
It refers to the absolute path and filename of the script that calls it. So, if I created a test script on my local machine, and say
I would get this
If, say for example I had 2 scripts, called test1.php and test2.php, and I included test2.php in test1.php like this
echo __FILE__.'<br />';
I would get this output
So it will always show the full path and filename of that script.
ok i see thanks. So its basically the same as $SERVER['phpself'] except it shows the full pathname on the server.
You can also use this for the same purpose:
Yup, exactly right
thanks, that is one mystery I can tick off the list
Not exactly like PHP_SELF. That will always point to the file requested by the browser. If you want to know the path to an include, not to the file that includes it, you would use FILE.
This topic is now closed. New replies are no longer allowed.