Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Get only directory path

I have:

$page_file_temp = $_SERVER["PHP_SELF"];

which will output: /templates/somename/index.php

I want to extract from that path only "/templates/somename/"

How can I do it? Thanks!

like image 577
Adrian M. Avatar asked Apr 08 '10 17:04

Adrian M.


People also ask

How can I get root directory path in PHP?

In order to get the root directory path, you can use _DIR_ or dirname(). echo dirname(__FILE__); Both the above syntaxes will return the same result.

What is __ DIR __ in PHP?

The __DIR__ can be used to obtain the current code working directory. It has been introduced in PHP beginning from version 5.3. It is similar to using dirname(__FILE__). Usually, it is used to include other files that is present in an included file.

How do I echo a directory in PHP?

PHP dirname() Functionecho dirname("c:/testweb/home. php", 2) . "<br />"; echo dirname("/testweb/home.

How do I get to the root directory in path?

You can change to the root directory of the current drive with the “cd” command or switch to a root directory on another drive. The root directory is the top-most folder on the drive. For example, “C:\” is the root directory for the C: drive and “D:\” is the root directory for the D: drive.


1 Answers

$page_directory = dirname($page_file_temp);

See dirname.

like image 161
David Avatar answered Sep 28 '22 14:09

David