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.

2 Answers 2

34
__FILE__

https://www.php.net/manual/en/language.constants.predefined.php

Sign up to request clarification or add additional context in comments.

1 Comment

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.