views:

982

answers:

3

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.

+5  A: 

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__).

shadowhand
A: 

Unfortunatly this does not work on a setup with multiple linked servers. __FILE__ shows the actual filename, but the path can be different that DOCUMENT_ROOT. On some servers this causes a 500 server error.

I have not found a way yet to find the filename of the current included file relative to DOCUMENT_ROOT.

JV