omg
omg

Reputation: 139842

How to get the directory of file inside itself with PHP?

A.php:

<?php

...

?>

How to know the directory within itself?

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

Upvotes: 0

Views: 180

Answers (4)

GZipp
GZipp

Reputation: 5416

And to change separators to the correct one:

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

Upvotes: 1

mauris
mauris

Reputation: 43619

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

Upvotes: 3

Lukman
Lukman

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

Artem Russakovskii
Artem Russakovskii

Reputation: 22013

dirname(__FILE__)

dirname reference.

Upvotes: 7

Related Questions