Reputation: 13298
my executed file is in
/homez.x/user/www/file.php
I need a function to only get
/homez.x/user/
fair enough I can build a function stripping $_SERVER['document_root'] without the last folder, but need to know if is there only one method to achieve this
Upvotes: 0
Views: 79
Reputation: 20045
By hardcoding a directory structure you lessen the reusability of your code.
So what I would recommend is to add this directory-level to your include_path somewhere central - php.ini or by using set_include_path.
fopen, file & Co will look for the file in the "included paths" if you provide them with the propper flags.
Upvotes: 0
Reputation: 7656
I'd merely do this:
$path = '/home/' . trim(`whoami`);
See also: shell_exec()
Upvotes: 3
Reputation:
/homez.x/user/
isn't the root of the filesystem -- /
is. Are you looking for the home directory, or just the parent of the document root? (They may not be the same at all.)
The former can be determined using posix_getpwuid()
. The latter is simply dirname($_SERVER["DOCUMENT_ROOT"])
.
Upvotes: 0