19

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.

Charles
  • 50,943
  • 13
  • 104
  • 142
Andy
  • 17,423
  • 9
  • 52
  • 69

2 Answers2

34
__FILE__

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

AndyMcKenna
  • 2,607
  • 3
  • 26
  • 35
  • 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`. –  Nov 23 '09 at 23:01
22

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
  • 3,202
  • 19
  • 23