473,761 Members | 3,542 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 39252
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
1624
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
1566
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 will change. I've got things set up and working on my dev box but have some questions.
11
2001
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 supposed to do when you're only allowed one site my relative URL's refer to the root of the
4
7575
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 root folder (for security purposes). When writing the files I understand how to use MapPath to...
1
1476
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 current date and time -- test.aspx. I can browse plain html files in the same directory without any...
0
1616
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 access to the share. (The login I run under is a member of that group.)
1
5341
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
2527
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 instead and converted one of the virtual roots that is a seperate
8
1842
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 they are ready to be deployed to a production webserver (IIS 6.0). I want the first app to be run...
3
1382
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 site forces me to use absolute referers such as "/file.jpg" in a href and img src attributes, which...
0
9377
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9989
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7358
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
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
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.