SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
Thread: what is __DIR__ ?
-
Dec 16, 2007, 21:36 #1
- Join Date
- Aug 2006
- Posts
- 94
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
what is __DIR__ ?
Sometimes when I look at other peoples PHP code they have something like this in there:
include(__DIR__"file.php");
what is __DIR__?
Thanks.
-
Dec 16, 2007, 21:41 #2
- Join Date
- Dec 2007
- Location
- Mackay, QLD, Australia
- Posts
- 158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
PHP Code:define('__DIR__', pathinfo(__FILE__, PATHINFO_DIRNAME));
-
Dec 16, 2007, 21:51 #3
- Join Date
- Aug 2006
- Posts
- 94
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
sorry yes i meant __FILE__
I dont quite get it - this refers to the filename of the PHP script or something else?
-
Dec 16, 2007, 21:57 #4
- Join Date
- Dec 2007
- Location
- Mackay, QLD, Australia
- Posts
- 158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
PHP Code:echo __FILE__;
C:\Apache2\htdocs\test.php
If, say for example I had 2 scripts, called test1.php and test2.php, and I included test2.php in test1.php like this
test1.php
PHP Code:<?php
include('test2.php');
echo __FILE__;
?>
PHP Code:<?php
echo __FILE__.'<br />';
?>
C:\Apache2\htdocs\test2.php
C:\Apache2\htdocs\test1.php
So it will always show the full path and filename of that script.
-
Dec 16, 2007, 23:05 #5
- Join Date
- Aug 2006
- Posts
- 94
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok i see thanks. So its basically the same as $_SERVER['php_self'] except it shows the full pathname on the server.
-
Dec 16, 2007, 23:05 #6
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You can also use this for the same purpose:
PHP Code:echo $_SERVER['SCRIPT_FILENAME'];
Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Dec 16, 2007, 23:06 #7
- Join Date
- Dec 2007
- Location
- Mackay, QLD, Australia
- Posts
- 158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Dec 16, 2007, 23:36 #8
- Join Date
- Aug 2006
- Posts
- 94
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanks, that is one mystery I can tick off the list
-
Dec 17, 2007, 12:00 #9
- Join Date
- Nov 2004
- Location
- Lincoln Nebraska
- Posts
- 1,161
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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__.
Bookmarks