Warwick
Warwick

Reputation: 945

PHP: Show directory NAME and not a period (".")

How do I get PHP to return the NAME of the current directory that the php file is in, and not "."?

What we're doing is having one master index file copied to each folder and presenting the images it finds in each folder necessarily. Now we need to remind the user what folder they're currently in!

Thanks

Upvotes: 1

Views: 892

Answers (4)

julesj
julesj

Reputation: 754

use __DIR__ or, before PHP 5.3, dirname(__FILE__)

Upvotes: 4

xzyfer
xzyfer

Reputation: 14135

Have you tried getcwd

<?php

// current directory
echo getcwd();

Or realpath as mentioned below. realpath is generally more useful as you are not restricted to the current working directory.

Upvotes: 3

Mat
Mat

Reputation: 206841

You can use the realpath function for that.

Upvotes: 3

Dor
Dor

Reputation: 7494

Use basename(realpath('.')), See:

Upvotes: 4

Related Questions