mameha — 2007-12-16T22:36:25-05:00 — #1
Sometimes when I look at other peoples PHP code they have something like this in there:
what is DIR?
lamiunto — 2007-12-16T22:41:48-05:00 — #2
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.
mameha — 2007-12-16T22:51:04-05:00 — #3
sorry yes i meant FILE
I dont quite get it - this refers to the filename of the PHP script or something else?
lamiunto — 2007-12-16T22:57:04-05:00 — #4
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.
mameha — 2007-12-17T00:05:15-05:00 — #5
ok i see thanks. So its basically the same as $SERVER['phpself'] except it shows the full pathname on the server.
raju_gautam — 2007-12-17T00:05:58-05:00 — #6
You can also use this for the same purpose:
lamiunto — 2007-12-17T00:06:27-05:00 — #7
Yup, exactly right
mameha — 2007-12-17T00:36:47-05:00 — #8
thanks, that is one mystery I can tick off the list
hammer65 — 2007-12-17T13:00:12-05:00 — #9
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.