2 problems with paths.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
a_marko
Forum Newbie
Posts: 4
Joined: Fri Apr 02, 2004 6:37 am
Location: Finland

2 problems with paths.

Post by a_marko »

Hi,

I have two really trivial sounding problems with paths. I am constructing a site on my Windows box with Minixampp (i.e. Apache) which I then move to my ISP (Unix with Apache). On some pages I'd like to use paths that are relative to my html root directory, e.g /Navigation/TreeMenu.php.

I have Images directory for images and TreeMenu directory for navigation menus.

I'm using the following looking code in practically all pages to set up the navigation, background, banner etc.

Code: Select all

<script src="/Navigation/TreeMenu.js" language="JavaScript" type="text/javascript"> </script>
<link href="/Navigation/TreeMenuMyStyle.css" rel="stylesheet" type="text/css">
<body background="/Images/GrayBackground.jpg">
<img border="0" src="/Images/MyBanner.jpg" width="790" height="92">

<?php require_once( '/Navigation/TreeMenuMySite.php' ); ?>
1) This works halfway on the windows box. It will load the images but the PHP require will fail. Why such different behaviour regarding the path in PHP? The HTML portion did find and load the .js and .css with similar path specifications!

2) On the Unix this doesn't work at all. I know the reason for it is that on my machine $_SERVER['DOCUMENT_ROOT'] gives e:\minixampp\htdocs which is the root of my web pages, whereas on the Unix it gives something like /opt/apache/htdocs which isn't my personal html root. How should I set the paths so that filenames e.g. /Images/MyBanner.jpg would work both on my local machine and on the ISP??

Thanks for any assistance!
- Marko

P.S Cheers to the TreeMenu(XL) authors!
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

require/include both use the include_path to search for the file to include. So check the include_paths on both servers, a <?php echo ini_get('include_path'); ?> will show you the paths it's searching.
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

PHP doesn't seem to recognize root ('/') in pathing. change it to

Code: Select all

<?php require_once( 'Navigation/TreeMenuMySite.php' ); ?>
and that will solve one of your problems. Although if anyone knows how to make PHP recognize root, that would be really good to know.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

./ i believe.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

LiLpunkSkateR wrote:./ i believe.
correct.
Post Reply