473,473 Members | 1,824 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Site Root directory?

Rv!
I've posted this onto alt.php earlier and stumped all involved.
I didn't cross post for the usual reasons Anyone here got any ideas?
--------------------------------------
I am simply attempting to find my sites root directory so I can then step up
into a folder
in which I will have my INCLUDE code. This will allow me to easily refer to
my
INCLUDE code without messing about.

Now, This code...

It simply attempts to put a file into the root of my server space, and
recall it. It doesn't work.

The file write doesn't error and the file read fails without error.
Most importantly the file is nowhere to be seen!

<Added when sent to the domain provider>
--------------------------------------
I am worried the file is dropping into a space not allocated to my account
and that
this could cause you/I some problems if it were to overwrite an important
file.
--------------------------------------
</Added when sent to the domain provider>

Robertv!


<?

$file="/tempfile.test";

#write a file to the server.
$thefile = fopen($file,"w");
fwrite ($thefile,"If you see this the file was successfully written to, and
re-read from the server as filename: $file") ;
fclose ($thefile);

#read the file from the server.
$thefile = fopen($file,"r");
$readdata=fread ($thefile,100000) ;
fclose ($thefile);
#display the results.
echo "Data file when read was :<HR>";
if($readdata=="")
{echo "Data came back empty. The file could not be read, and may not have
been written."; }
{echo $readdata."</HR>" ;}

#
#
#User comments...
# $file="tempfile.test"; will write to the current directory.
# $file="../tempfile.test"; will write up one directory.
# $file="/tempfile.test"; does some crazy disappearing act.
# Server phpinfo() snip...Windows NT localhost 5.2 build 3790
Jul 17 '05 #1
4 39231
Rv! wrote:

I am simply attempting to find my sites root directory so I can then step up
into a folder
in which I will have my INCLUDE code. This will allow me to easily refer to
my
INCLUDE code without messing about.

Now, This code...

It simply attempts to put a file into the root of my server space, and
recall it. It doesn't work.

The file write doesn't error and the file read fails without error.
Most importantly the file is nowhere to be seen!

<Added when sent to the domain provider>
--------------------------------------
I am worried the file is dropping into a space not allocated to my account
and that
this could cause you/I some problems if it were to overwrite an important
file.
--------------------------------------
</Added when sent to the domain provider>

Robertv!


<?

$file="/tempfile.test";
// Oops, first, this needs to be a system path, not a URI

$file=$_SERVER['DOCUMENT_ROOT'].'/tempfile.test';
#write a file to the server.
// should check if the file is writable
// (this means that the file must exist and have proper rights on the
// file system for the user that the webserver is running as)

if(is_writable($file)){
$thefile = fopen($file,"w");
fwrite ($thefile,"If you see this the file was successfully written to, and
re-read from the server as filename: $file") ;
fclose ($thefile);
}else{
echo 'The file is now writable by the webserver user.';
}
// Should check if it is readable as well.
if(is_readable($file)){
#read the file from the server.
$thefile = fopen($file,"r");
$readdata=fread ($thefile,100000) ;
fclose ($thefile);
}else{
echo 'Cannot read the file.';
}
#display the results.
echo "Data file when read was :<HR>";
if($readdata=="")
// need to modify this line now
if(!isset($readdata))
{echo "Data came back empty. The file could not be read, and may not have
been written."; }
{echo $readdata."</HR>" ;}


HTH

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #2
Rv!

Hmm. This is bringing back the entire path to my PHP that called
the lookup. ie.
\\nas04ent\domains\m\<MYDOMAIN>\user\htdocs\<FIRST DIRECTORY>\soft\soft.php

Interesting. I might just parse the file backwords until I get to the
\htdocs\ parts and add
a directory onthe end so it looks like
\\nas04ent\domains\m\<MYDOMAIN>\user\htdocs\librar y
where library is the directory I would like to call the include file from.
Seems a lot of hassle as I believ the / should throw me to the root folder
of my system,
not the bleeding servers entire data set! :(

I'm digging further now. Thanks for that input!

Robert

Jul 17 '05 #3
Rv!
So.. I stripped back the servers response to the text...
"\\nas04ent\domains\m\<MYDOMAIN>\user\htdocs"
and I attacked the text "\library" and tried to write a file to
it as...
"\\nas04ent\domains\m\<MYDOMAIN>\user\htdocs\libra ry\test.file"
and it failed with unwritable!

It seems I can't find my ROOT by that method either.
This is driving me nuts as it is virtually impossible for me to add my
includes to point to a file in another folder. I have to sit there and
count back down the folders and type in the right amount of
"../../../../library/code.txt"
until the bloody thing works!
Sick sick sick sick sick. I'm off to get a beer.

Robert

Jul 17 '05 #4
Rv!
I've been in discussion with the hosts who suggested I use their server
path as the include.. \\NAS01\users\m\<DOMAIN>\htdocs\...." etc
which would force me to hardcode the PHP code and stop me testing it
on anything other than their server. Instead if doing this I've written a
shart
directory crawler which will search out the include code.. It, and a message
originally sent to alt.php are included below...


Just thought about what they want me to do.
I would need to hardcode my program to use their
path command which would fail out on local tests or on moving to
another server etc. I've decided not to use their system. Sat down
for half an hours and wrote this simple function which will search
back directories looking for the file or failing after a short search.

It might not be great but it works on all tested systems (Their IIS Win2K3
and my Apache Win2Kas). Please excuse the coding if it's bad, but I'm
still learning this stuff! ;) Code is broken into little sections just to
see it clearer
when sending here.

Hope this seems a reasonable solution to the more experienced folkseses?
Any comments much appreciated.

Robert

<?
#find the include file! Preset the $inc value to the part of the path
we know.
#strlen part sets a maximum path length to force exit if file search
is unsuccessful.
?>
<? $inc="library/_usefulcode.txt";
while(!file_exists($inc) && strlen($inc)<70 ) { $inc="../".$inc;}

#check if the file actually exists or if we crashed out.
if (!file_exists($inc)) {die ("Include file could not be found in expected
path.");}?>
<?
#Display the path we found our file in!
echo "Include path is $inc so let's get it and use a function...<BR>";
require $inc;
echo GETTIME();
?>
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Larry Woods | last post by:
I have defined a virtual directory and application called Test. The directory is C:\inetpub\wwwroot\Test. I created a trivial page: <% response.write Server.Mappath("/") %> When I execute...
2
by: engwar1 | last post by:
I'm a .NET newbie and am beginning the process of converting an existing personal website to .NET from classic ASP. I'm assuming I want my aspx files in the root of my site in the same place as...
11
by: Simon | last post by:
Hi all As I'm sure is common knowledge the version of IIS included in XP Pro is limited in that you can only create 1 website in the IIS snap in. As an ASP.net developer this is a pain in the...
4
by: Jerry | last post by:
I'm having just a bit of trouble wrapping my brain around the task of working with folders that are above the site's root folder. I let users upload photos (.jpg/.gif files) which can...
1
by: Tim Wood | last post by:
I'm having trouble with setup of an asp.net application on Windows 2003. When I attempt to start the app I get "Server Error in '/MyApp' application. The message also says that error details cannot...
0
by: Peter D. Dunlap | last post by:
I have a number of web sites on my 2003 server, each of the independent sites (i.e., not subdirectories of the localhost site). The way I have always set these up in the past is: 1. Create a...
1
by: John Dalberg | last post by:
I have an asp.net app that is in a folder which is two levels under the website root folder. The website has a login.aspx which is in the root folder. How do I get the relative path to the web...
5
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
8
by: news.microsoft.com | last post by:
I have two completely distinct ASP.NET (2.0) web applications. They share no code, they have distinct web.config files, they don't even link to each other. During development, they have lived...
3
by: Erik ETS | last post by:
I need some symmetry between my development environment and my running web site. The root of my web site is http://www.mysite.com/ while the root of the project in my local development environment...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.