Click to See Complete Forum and Search --> : I'm looking for two predefined variables...


hammerslane
10-11-2005, 10:42 AM
Scenario: The script location is at /home/server/e/example.com/htdocs/folder/contact.php on the server.

Question: does a predefined variable exist which contains either of these values:

'contact.php'
'/folder/'


$_SERVER['PHP_SELF'] is the closest I can find - but that's just a combination of the two.

If predefined variables do not exist for either of these values, is there a way to create a variable containing them?

If there is no way to create either of these variables, please let me know.

Thanks very much for reading my post.

NogDog
10-11-2005, 12:32 PM
You can parse it fairly easily:

<?php
$parts = explode('/', $_SERVER['PHP_SELF']);
$file = array_pop($parts);
$path = implode('/', $parts) . '/';
echo "<p>path: $path</p>\n";
echo "<p>file: $file</p>\n";
?>

hammerslane
10-11-2005, 01:09 PM
Thanks NogDog.

I remember thinking of that option, but quickly dismissing it, "because what if the file name contained a forward slash?"
I now realise that I am an idiot.

SpectreReturns
10-11-2005, 09:32 PM
Or you coud use base_file and base_dir.

Daniel T
10-11-2005, 11:18 PM
The not-so-messy way, with PHP's predefined __FILE__:
$file = basename(__FILE__);
$folder = dirname(__FILE__);
;)