473,547 Members | 2,476 Online
Bytes | Software Development & Data Engineering Community
+ 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,10000 0) ;
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 39238
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,10000 0) ;
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($read data))
{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\doma ins\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\doma ins\m\<MYDOMAIN >\user\htdocs\l ibrary
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\dom ains\m\<MYDOMAI N>\user\htdocs "
and I attacked the text "\library" and tried to write a file to
it as...
"\\nas04ent\dom ains\m\<MYDOMAI N>\user\htdocs\ library\test.fi le"
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>\htdoc s\...." 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_exi sts($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
1619
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 this page I get: C:\inetpub\wwwroot\
2
1553
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 my asp files. In this way when I eventually get switched over to all aspx files my URLs will not have an extra directory name, only the extensions...
11
1982
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 arse because I can't figure out how to stop having this fact cock up my relative urls. When I create a virtual directory - presumably what you're...
4
7561
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 subsequently be viewed on the site's pages. My hosting provider is requiring that any files my Web app writes get written to a folder that is above the app's...
1
1468
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 be displayed because customErrors is set to remoteOnly in web.config. Right now the application consists of a single page that displays the...
0
1606
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 directory "MySiteName" and a subdirectory "Site". 2. Share the "Site" subdirectory is "MySiteNameSite$", and give the local administrators group full...
1
5334
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 site root folder (not the curent app folder)? A generic one that works no matter how deep the folder is in the folder heirarchy --
5
2501
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 applications. I am testing an upgrade of all of the sites and have converted the main root site...although not necessarily fixed any issues. I move on...
8
1829
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 happily side by side in two virtual directories in the same IIS website. e.g. http://localhost/dotnetnuke and http://localhost/mobilephoneapp Now...
3
1367
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 is http://localhost/myproject/, differing from the local server root http://localhost/. This means a lot of trouble since some url rewriting on my...
0
7510
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main...
0
7703
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7463
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7797
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1923
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 we have to send another system
1
1050
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
748
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.