note 68017 modified in function.dirname by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 19:04:39 +0000 |
| Subject: | note 68017 modified in function.dirname by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142262@lists.php.net to get a copy of this message | ||
The best way to get the absolute path of the folder of the currently parsed PHP script is:
<?php
if (DIRECTORY_SEPARATOR=='/')
$absolute_path = dirname(__FILE__).'/';
else
$absolute_path = str_replace('\\', '/', dirname(__FILE__)).'/';
?>
This will result in an absolute unix-style path which works ok also on PHP5 under Windows, where
mixing '\' and '/' may give troubles.
[EDIT by danbrown AT php DOT net: Applied author-supplied fix from follow-up note.]
--was--
The best way to get the absolute path of the folder of the currently parsed PHP script is:
<?php
if (DIRECTORY_SEPARATOR=='/')
$absolute_path = dirname(__FILE__).'/';
else
$absolute_path = str_replace('\\\\', '/', dirname(__FILE__)).'/';
?>
This will result in an absolute unix-style path which works ok also on PHP5 under Windows, where
mixing '\' and '/' may give troubles.
http://php.net/manual/en/function.dirname.php