Filesystem PHP

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
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Filesystem PHP

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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";
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post 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.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post 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;
Post Reply