Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 02-28-2008, 05:45 PM Find Directory Path
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
How can I find the directory path on my server. I need this to include scripts from the root directory AND from my includes folder which is on the root directory.

Anyone know how to find the directory path?
Gilligan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-28-2008, 05:51 PM Re: Find Directory Path
Registered User

Posts: 73
Trades: 0
from your root directory call : realpath('.')
nanimo is offline
Reply With Quote
View Public Profile
 
Old 02-28-2008, 06:04 PM Re: Find Directory Path
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
I though it might display that, not working when I include it though, says that there is no such file.

Is the any predefined variable that uses the directory root?
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 02-28-2008, 06:11 PM Re: Find Directory Path
Registered User

Posts: 73
Trades: 0
to call your include scripts from a "includes" directory just call

PHP Code:
realpath('.')."/includes/yourscript.php"
nanimo is offline
Reply With Quote
View Public Profile
 
Old 02-29-2008, 12:57 AM Re: Find Directory Path
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
$_server['document_root'] ?
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 02-29-2008, 12:58 AM Re: Find Directory Path
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Dammit.

PHP Code:
 $_SERVER['DOCUMENT_ROOT'
Dumb script lowercased my message for some reason.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 02-29-2008, 03:22 AM Re: Find Directory Path
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
Both include fine when trying to include a script from the root directory, but how would I include a script that is in my includes folder from a folder inside a folder.

Example:

http://www.mysite.com/includes/config.php

How would I include this from

http://www.mysite.com/folder1/folder2/index.php

Thanks
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 02-29-2008, 03:36 AM Re: Find Directory Path
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
You cannot include http://www.mysite.com/includes/config.php from http://www.mysite.com/folder1/folder2/index.php. You can include /usr/www/sites/mysite.com/includes/config.php from /usr/www/sites/mysite.com/folder1/folder2/index.php. That is the first. Now you should obtain the full absolute path to your document root which in this case will be /usr/www/sites/mysite.com, and resolve your relative paths from that absolute path:
PHP Code:
include $_SERVER['DOCUMENT_ROOT'].'/includes/config.php'
To avoid problems with refering to local files by relative paths you should always refer to them by absolute path. It is not necessary to have a $_SERVER['DOCUMENT_ROOT'] as root folder, you can define some other variable in a script which is included by each and every script, e.g. common.php, which would contain something like following:
PHP Code:
if (!isset($_SERVER['DOCUMENT_ROOT']))
   
$_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__); 
Obviously $_SERVER['DOCUMENT_ROOT'] can be not set if you run your script from command line, because it is apache variable passed to php as module.

Problem of relative paths is the most popular one on this forum for the last month. And I guess it will remain the most popular forever. If you could read in Russian I'd recommend one very good article about php which clears out how php works, what php can and what it can not. But I definitely won't translate it.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 02-29-2008, 12:07 PM Re: Find Directory Path
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
So which code should I put in each file, sorry, kinda new with php.

EDIT

Nevermind, I was upgrading the server, that's why I had problems. Working now with using folders.

Last edited by Gilligan; 02-29-2008 at 12:28 PM..
Gilligan is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Find Directory Path
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.66914 seconds with 12 queries