tags:

views:

87

answers:

4

A.php:

<?php

...

?>

How to know the directory within itself?

EDIT On windows,how to change "\" to "/"?

+6  A: 

dirname(__FILE__)

dirname reference.

Artem Russakovskii
+3  A: 

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)

Lukman
+3  A: 

By the way, you can get the correct "/" or "\" on any platform by using the DIRECTORY_SEPARATOR constant

thephpdeveloper
+1  A: 

And to change separators to the correct one:

$filepath = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $filepath);
GZipp