...

View Full Version : Displaying filename w/ dir info (resolved)



PaulC2K
02-11-2006, 06:20 AM
Is it possible to display purely the filename of the file which is currently on screen?

"__FILE__" does more than i'd care for it to do, I dont need to know the masses of directories before it, just *.php would be wonderfull!


Is it possible to have a value and deduct specific text from it?

Could i do something like


$fullfilename = __FILE__ ; // (/home/username/public_html/domain/filename.php)

$shortfilename = $fullfilename - "/home/username/public_html/domain/";

I know the above wont work, but thats effectively what i want (clearly i should start my own programming language!! :thumbsup: ) but ive no idea if something like that is out there?

Basically im desperate just to have the filename alone, any care to put me out of my misery? :D

Cheers,
PaulC2K

dumpfi
02-11-2006, 01:37 PM
See basename() (http://www.php.net/manual/en/function.basename.php)

dumpfi

raf
02-11-2006, 01:43 PM
basename($_SERVER['PHP_SELF'])

marek_mar
02-11-2006, 02:48 PM
I'll just might add that $_SERVER['PHP_SELF'] and __FILE__ work a bit different.


// index.php
<?php
print 'basename(__FILE__): ' . basename(__FILE__) . "<br />\n";
print 'basename($_SERVER[\'PHP_SELF\']): ' . basename($_SERVER['PHP_SELF']) . "<br />\n";
print 'Now for include.php' . "<br />\n";
include 'include.php';
?>
// include.php
<?php
print 'basename(__FILE__): ' . basename(__FILE__) . "<br />\n";
print 'basename($_SERVER[\'PHP_SELF\']): ' . basename($_SERVER['PHP_SELF']) . "<br />\n";
?>

The result of that would be:


basename(__FILE__): index.php
basename($_SERVER['PHP_SELF']): index.php
Now for include.php
basename(__FILE__): include.php
basename($_SERVER['PHP_SELF']): index.php

__FILE__ holds the file which is being currently parsed and $_SERVER['PHP_SELF'] holds always the first php file.

PaulC2K
02-11-2006, 11:58 PM
Guys, your superstars!!
Had a rumage round php.net using 'file' and 'filename' to see if that brought any luck, figured there must be a straight forward way to get the result i needed but '__FILE__' didnt point me in the direction of 'basename' and i knew i could count on you guys :)

Thanks for the help :thumbsup:

raf
02-12-2006, 10:06 AM
you're welcome!

interesting addition from marek_mar --> i only use '__FILE__' for debugging and errorreporting purposes. For selfreferencing functionalitys (like forms that post to themselves or to prevent direct requests to include-files), i always use $_SERVER['PHP_SELF']



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum