Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get name of current PHP script in include file

Tags:

php

I have files served like so:

AJAX request handler -> Include file

I would like to retrieve the name of the include file within the include itself. Neither $_SERVER['PHP_SELF'] or $_SERVER['SCRIPT_NAME'] is suitable for this, as they return the "parent" script name.

Thanks.

like image 299
Andy Avatar asked Jul 02 '09 15:07

Andy


2 Answers

__FILE__

http://us3.php.net/manual/en/language.constants.predefined.php

like image 100
AndyMcKenna Avatar answered Oct 24 '22 16:10

AndyMcKenna


If you want only the name part of the file (without the directory) you can use basename(__FILE__) or for just the directory dirname(__FILE__).

like image 20
shadowhand Avatar answered Oct 24 '22 17:10

shadowhand