Free Web Hosting Forum
(#1 (permalink))
Old
Junior Member
Kethaias is on a distinguished road
 
Posts: 2
Join Date: Apr 2012
Default Root Directory Pathing Issue - 04-29-2012, 09:22 PM

Whenever I use a "/" at the beginning of a path (to reference the root directory) when including a file using the php include function it comes up with an error saying that it could not be found. Perhaps I am not using it correctly. I am using:
Code:
<?php
include('/navbar.php');
?>
the file is in my public_html folder and can be accessed directly from there or by using "../navbar.php" from the a sub folder. I am including this from many locations in my site and would prefer not to use ../../../ everytime. I guess my questions are:
1. Am I using the "/" path correctly?
2. If so, what am I doing wrong when pathing to my file?
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
nevermore93's Avatar
Senior Member
nevermore93 is on a distinguished road
 
Posts: 298
Join Date: Dec 2011
Location: USA
Default 04-29-2012, 10:29 PM

There is a way to reference the"root" with PHP, but it's not allowed here and has been disabled. For now, you're stuck with relative URLs on your includes.

If the file calling the include is in the root directory as well, then either of the following will work:
Code:
include('navbar.php');

OR

include('./navbar.php');


Reply With Quote
(#3 (permalink))
Old
Junior Member
Kethaias is on a distinguished road
 
Posts: 2
Join Date: Apr 2012
Default 04-29-2012, 11:39 PM

Quote:
Originally Posted by nevermore93 View Post
There is a way to reference the"root" with PHP, but it's not allowed here and has been disabled. For now, you're stuck with relative URLs on your includes.

If the file calling the include is in the root directory as well, then either of the following will work:
Code:
include('navbar.php');

OR

include('./navbar.php');
Thank you I thought it would be something like that since it was working with relative simplicity when using localhost. I guess I'll just design a short php function that will determine the nesting level of the current document and use relative links. Thanks for your help.
Reply With Quote
Reply

Tags
directory, issue, php, public_html, root

Thread Tools
Display Modes

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




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com