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
Managing relative paths with different directories
Old 05-03-2009, 02:21 AM Managing relative paths with different directories
Skilled Talker

Posts: 90
Trades: 0
Hi all,

I'm new to php and trying to design my first site with it. My basic template uses includes for the header and footer, but what I'm confused about is using that same template in other directories.

If index.php is in the root folder, along with header.php (which includes all the relative links to my CSS files and so on), how can I use that same template for a folder in say, root/directory2/?

The problem I run into is, I can change the relative paths to the include files, IE: <? include ('../header.php'); ?> ... but I still have the issue of then the CSS links are wrong when they're brought into that directory.

I'm not sure if that makes sense... but basically I can't figure out an easy way to manage these files in other directories and it seems like just putting all the files in the root would be easiest -- though that's not optimal.

Is there a way to do this without using absolute paths to files or putting all the pages using the template in the root?

Thanks in advance!
msaz87 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-03-2009, 02:50 AM Re: Managing relative paths with different directories
GeekSpecialties's Avatar
Super Talker

Posts: 132
Name: Leonard
Location: Minnesota, USA
Trades: 0
You can make you links root relative.

/directory/file

Drop the ../ (subdirectory indicator) for /
The beginning / indicates the root directory, so no matter where the file is linked from the path starts at the root.
GeekSpecialties is offline
Reply With Quote
View Public Profile Visit GeekSpecialties's homepage!
 
Old 05-03-2009, 03:07 AM Re: Managing relative paths with different directories
Skilled Talker

Posts: 90
Trades: 0
Sorry -- I think I shouldn't have used the root as an example. The directory structure will look more like this:

root/location1_directory/
root/location1_directory/index.php
root/location1_directory/css/styles.css

root/location2_directory/
root/location2_directory/index.php
root/location2_directory/css/styles.css

So it's really kind of different sites for each location, but with individual stylesheets that sit in directories not on the root. I assume if I had "/css/styles.css" for any of those, it would error since there isn't a css directory off the root.

Hope that makes sense... thanks for the help!
msaz87 is offline
Reply With Quote
View Public Profile
 
Old 05-03-2009, 12:15 PM Re: Managing relative paths with different directories
GeekSpecialties's Avatar
Super Talker

Posts: 132
Name: Leonard
Location: Minnesota, USA
Trades: 0
It's still root relative how you put it. Just take off the root text from your example links and you have it.

/location1_directory/css/styles.css

This beginning / by itself means start at root.
/ (start at root) location1_directory (look in location1_directory) /css (look in css) /styles.css (get file styles.css)
GeekSpecialties is offline
Reply With Quote
View Public Profile Visit GeekSpecialties's homepage!
 
Reply     « Reply to Managing relative paths with different directories
 

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.34850 seconds with 12 queries