This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes PHP and the fly likes Directory structure issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Languages » PHP
Bookmark "Directory structure issue" Watch "Directory structure issue" New topic
Author

Directory structure issue

chanveil Kiji
Greenhorn

Joined: Dec 30, 2010
Posts: 15
I currently have a website that was thrown together w/o planning and I am now trying to begin organizing it a little better. The issue I'm having is that I want to move some of the pages into subdirectories, but other pages (such as the main page) will still remain in the root directory. I have a directory called includes that holds the header file, footer file, and navigation files which are included in all pages within the site. My problem is that when I am on a page within the root directory, or a page within the sub directory, the path's need to be different for the links and image files.

For instance, if a page in the root directory is displayed to link to another page I can just link to "example.php", but if i'm on a page within a subdirectory the link needs to be "../example.php".

Only using one file to hold all the link information, is there a simple way to do this?
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 1963
    
    7

There is a way = to use a so-called configuration file where you define "constants" pointing the correct paths for different cases

For example assuming your directory looks like this
/webroot
/webroot/images
/webroot/subdir1
/webroot/subdir1/subdir2
/webroot/index.php

//subdirectory paths
$SUB1_IMAGE_PATH = "../images"; // for subdir1
$SUB2_IMAGE_PATH = "../../images"; // for subdir2

//root paths
$IMAGE_PATH = "images"; // for index.php

A warning about this approach: as more directories are added maintaining this file can be tedious and error-prone. Also this can be error-prone when programming pointing to the wrong constant so naming convention must be defined and follow through.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Directory structure issue
 
Similar Threads
HMTL Pages access from Apache Web Server
"Applet not initiated" in Tomcat 3.3
Running jsp pages in IIS web directory
Delete genterated Files
How to set up a relative path