Page 1 of 1

Filesystem PHP

Posted: Sun Jul 15, 2007 9:23 am
by tecktalkcm0391
Is there anyway to get what directory holds the folder that is accessible via the internet.

Example:
The script on /home/site/public_html/phpscript.php would return /home/site/ because the public_html folder holds the files accessible by internet users.

Posted: Sun Jul 15, 2007 9:44 am
by volka
I'm not sure what exactly you're looking for but you might want to try

Code: Select all

<?php
echo 'FILE: ', __FILE__, "<br />\n";
echo 'dirname(FILE): ', dirname(__FILE__), "<br />\n";
echo 'dirname(dirname(FILE)): ', dirname(dirname(__FILE__)), "<br />\n";
echo 'cwd: ', getcwd(), "<br />\n";
echo 'realpath(..): ', realpath('..'), "<br />\n";
echo 'realpath(../..): ', realpath('../..'), "<br />\n";

Posted: Sun Jul 15, 2007 9:49 am
by tecktalkcm0391
volka wrote:I'm not sure what exactly you're looking for but you might want to try

Code: Select all

<?php
echo 'FILE: ', __FILE__, "<br />\n";
echo 'dirname(FILE): ', dirname(__FILE__), "<br />\n";
echo 'dirname(dirname(FILE)): ', dirname(dirname(__FILE__)), "<br />\n";
echo 'cwd: ', getcwd(), "<br />\n";
echo 'realpath(..): ', realpath('..'), "<br />\n";
echo 'realpath(../..): ', realpath('../..'), "<br />\n";
Thanks! I'm gonna try this stuff. What I am looking for is the folder that all the pages that you can view on the internet. So if my files are all in \home\public_html I can get \home\ so i can make \home\protected_html.... I want this for a code installer I'm making.

Posted: Sun Jul 15, 2007 9:54 am
by tecktalkcm0391
I tried out your code and nothing returned what I'm looking for, but great information... I can use it for something else. :)

I think this will work:

Code: Select all

$folders = $_SERVER['DOCUMENT_ROOT'];
$p_folders = explode('/',$folders);
$c_folders = count($folders);
$folders = explode('/',$folders,($c_folders-2));
$folders = implode('/',$folders);

echo $folders;