Page 1 of 1
How to get the filename of the current file
Posted: Fri Dec 19, 2003 6:31 am
by vigge89
How can I get the filename of the current executed script?
IE, i want the script go get it's own filename, formatted "file.ext", no folders or anything else where it's located, just the filename of the file.
Posted: Fri Dec 19, 2003 6:35 am
by twigletmac
[php_man]basename[/php_man]() and $_SERVER['PHP_SELF'].
Mac
Posted: Fri Dec 19, 2003 6:37 am
by JayBird
try this
Code: Select all
<?
$file = basename ($_SERVER['PHP_SELF']);
echo "the script is called ".$file;
?>
Mark
Posted: Fri Dec 19, 2003 4:03 pm
by Weirdan
PHP manual wrote:
Table 4.1. A few "magical" PHP constants
Name Description
__LINE__ The current line number of the file.
__FILE__ The full path and filename of the file.
__FUNCTION__ The function name. (This was added in PHP 4.3.0.)
__CLASS__ The class name. (This was added in PHP 4.3.0.)
__METHOD__ The class method name. (This was added in PHP 5.0.0)
so you can try:
it will give you true filename even if the file is included from other one. $_SERVER['PHP_SELF'] won't.
Posted: Fri Dec 19, 2003 4:49 pm
by vigge89
so
Code: Select all
<?php
$file = basename ($_SERVER['PHP_SELF']);
?>
gives me the file running, ie; if i include 1file.php in 2file.php, it will output 2file.php? That's what i want, and I just wanna be sure before i go on with my scipt

.
Posted: Mon Dec 22, 2003 4:59 am
by twigletmac
test it
Mac