473,322 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Server variable $_SERVER["DOCUMENT_ROOT"]

Hi,
I am using the Linux Server and server variable $_SERVER["DOCUMENT_ROOT"] to get the root folder to open a text file located in the folder for ex.

fopen($_SERVER["DOCUMENT_ROOT"]."/folder/file.txt","r");
......


I want to use the same scripts to work with Windows Server, Is there any way to get the root folder of the domain installation in Windows?
like it should return c:\www


Could any one suggest me?

Thanks in advance

Sakthi
Dec 25 '07 #1
6 8664
pbmods
5,821 Expert 4TB
Heya, Sakthi.

$_SERVER['DOCUMENT_ROOT'] evaluates to the path to your server's document root regardless of operating system....
Dec 25 '07 #2
Heya,
I didn't find the variable $_SERVER["DOCUMENT_ROOT"] in the phpinfo() in the Windows server. How to enable this variable in Windows Server?

Sakthi
Dec 26 '07 #3
pbmods
5,821 Expert 4TB
Heya, Sakthi.

... except for Windows, it seems, which likes to make life difficult.

Do you have $_SERVER['ORIG_PATH_TRANSLATED'] by any chance?

Alternatively, if you have a file at the document root, you can use dirname(__FILE__).
Dec 27 '07 #4
Hi,
Its working in Windows, but is not the situation,
I want a single variable that returns the document root in both servers,
here the _SERVER["ORIG_PATH_TRANSLATED"] variable is not available in my Linux Server.

For ex,
1. In Linux Server it should refer /www/project
2. Where as in Windows Server it should return D:\www\project

where project is the root for the particular project

Suggest me

Sakthi
Dec 27 '07 #5
Heya,
Actually the problem with dirname(__FILE__) is,
When I call this from the root, ie. from /www/projects it solves the situation.

The problem is, when I call from the sub directory inside the root ie.

From /www/projects/aaa, I want to refer the path /www/projects/bbb, here the function returns /www/projects/aaa as result, so the final result will be,

dirname(__FILE__)."/bbb" = /www/projects/aaa/bbb which is wrong

Suggest me

Sakthi
Dec 29 '07 #6
pbmods
5,821 Expert 4TB
Heya, Sakthi.

Try creating a common include file in your document root:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     if( empty($_SERVER['DOCUMENT_ROOT']) )
  3.     {
  4.         $_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__);
  5.     }
  6. ?>
  7.  
Then simply include() this file at the top of any script that needs to use $_SERVER['DOCUMENT_ROOT'].
Dec 30 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: MeAndI | last post by:
How to everybody, how it is possible to change the value of the AUTH_USER server variable? Is this possible? If no, how I could change the logged user? Thanks for help
4
by: Bob T | last post by:
Hi All, I am trying to pass a variable from my VB asp.net script (from for example Sub Page_Load in mypage.aspx.vb) to my Client side script. I have found and looked at a very good example...
15
by: joun | last post by:
Hi all, i want to create in my asp.net application a custom server variable, so i can retrieve later in other pages (even asp or perl) with request.servervariables("HTTP_mycustomvariable") ...
1
by: Tillman | last post by:
I am working on reducing the size of the ViewState value passed between client and server in a web app. And I am asking myself why the ViewState value can't be stored in a server variable rather...
2
by: shil | last post by:
Hi all, I am using javascript confirm() function to get user's confirmation from codebehind after a condition is met. I don't want to attach the function to the button on page load. When I...
0
by: ndrw_cheung | last post by:
Hi, all. I recently migrated a website from IIS5.0 (running on Windows 2000 Server SP4) to IIS6.0 (running Windows Server 2003 SP1). The ASP.NET version is upgraded from 1.1 to 2.0 as well. I...
1
by: mbasil77 | last post by:
I'm trying to create a custom server variable in DOTNET. Is there a way to do this? I know there are MUCH better/easier ways to store session data ... However, I'm dealing with a legacy...
6
by: rlm51 | last post by:
Hey everyone, hope all are fine ... Dreamweaver uses a login_user server behavior to send the user to a specified page on a successful login. Normally you would provide a url, but I would like to...
8
by: doublestack | last post by:
I have a server variable that is being called from an aspx page in a WSS site. I need to find a way to remove part of the variable before passing it to the URL. The server variable is LOGON_USER......
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.