In article <[EMAIL PROTECTED]>, Tom
Rogers wrote:
> I am trying to calculate how far into a directory structure I am so that I 
> can include images and include files without having to hard code them.
> I need to turn $PHP_SELF which could be /admin/emails/index.php into ../../ 
> which I can then use to get to any directory from root.

Here's a more compact regexp:

preg_replace("|/[^/]+|", "../", dirname($_SERVER['PHP_SELF']));

dirname() returns only the directory part of a filename (e.g. "/~chris"
from "/~chris/myfile.php").

Using | instead of the usual / to delimit the regular expression just
saves a bit of typing.

(Note that for includes, you'd be better off setting include_path in
php.ini or .htaccess - that avoids the need to worry about where the
files are physically located)

If you need the local file path and you're using Apache, the
PATH_TRANSLATED variable can tell you where your files are:
$current_dir = dirname($PATH_TRANSLATED) . "/";

This could be used to construct absolute paths internally - I use it in
my photo gallery code when creating thumbnails & such with convert.
Using it with DOCUMENT_ROOT can help if you need to construct things
like directory listings.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to