How to Extract the filename of the current Document?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kearns
Forum Newbie
Posts: 1
Joined: Sun Jan 08, 2006 11:28 pm

How to Extract the filename of the current Document?

Post by kearns »

Hi, good day ...

I just want to ask how to extract a filename of the current document ? As of now, im building a php driven site and dont know how to extracty the filename of the current document im doing.

Here is the algorithm :

Example:

template.php - it will call an external php page called affad.php

affad.php - this will hold the code that will determine the category where the output appears base on the filename

My focus is how to extract the filename of the curent documant ...

Any help is deeply appreciated :

Thanks ...
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

mayhaps: __FILE__ ???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

__FILE__ is literally, the file where that text appears. It sounds like you want to know what script was called by the client. Have a look through $_SERVER, since the fields filled varies slightly from server to server. Fields that can exist and will contain the filename are (but not limited to) SCRIPT_NAME, PHP_SELF, REQUEST_URI
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

as feyd suggests, sounds like $_SERVER contains what you are after, in partciular $_SERVER['SCRIPT_NAME']

but do be warned, some of the fields in $_SERVER can be tainted unwantedly by the user - $_SERVER['PHP_SELF'] is one, as has been shown in a previous thread.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

If you just want the script of the corrent document, something like $_SERVER['PHP_SELF'] would suffice.

However if the document you want the URI of has a query string appended to it then you will need to request the query string from $_SERVER['QUERY_STRING'] and append it to the result of php_self
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

scrotaye wrote:If you just want the script of the corrent document, something like $_SERVER['PHP_SELF'] would suffice.

However if the document you want the URI of has a query string appended to it then you will need to request the query string from $_SERVER['QUERY_STRING'] and append it to the result of php_self
$_SERVER['REQUEST_URI'] does that for you.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply