Reputation: 139842
A.php:
<?php
...
?>
How to know the directory within itself?
EDIT On windows,how to change "\" to "/"?
Upvotes: 0
Views: 180
Reputation: 5416
And to change separators to the correct one:
$filepath = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $filepath);
Upvotes: 1
Reputation: 43619
By the way, you can get the correct "/" or "\" on any platform by using the DIRECTORY_SEPARATOR constant
Upvotes: 3
Reputation: 19119
dirname(__FILE__)
to get the path of the PHP file regardless of whether the file runs on its own or is being included by other files.
getcwd()
to get the current working directory (might not be the same as the directory the PHP file is in if it is being included by other files)
Upvotes: 3