Forum Moderators: coopster

Message Too Old, No Replies

Directory Structure

         

BobbyBudds

9:23 pm on Apr 18, 2005 (gmt 0)

10+ Year Member



First I want to thank you for taking the time to read this. Ok, I have my root context folder for my webapps in a folder called "mywebapp/html/" and in the html dir I have my index.php. I have an include statement in index.php that access a file from mywebapp/html/includes/somefile.php and it works. But when i go to a page like "mywebapps/html/modname/index.php" and it has the same include statement in it, it wont work.

I thought i could just put a relative path for that include in any file anywhere in my root and all subfolders but i guess not. Or maybe im just doing it wrong? Because i would hate to go include("../../somefile.php") instead of just include ("somefile.php");

ergophobe

9:59 pm on Apr 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



My preferred solution is absolute URLs everywhere and full file paths. I think it's the most failsafe and, unless you have a zillion links, it doesn't really add much to page weight.

So I usually do my links roughly like this

$href = $_SERVER['HTTP_HOST'] . '/dir/page.php';
$include_file = $_SERVER['DOCUMENT_ROOT'] . '/dir/page.php';

You may also set the include_path [us4.php.net] directive in php.ini or .htaccess.

jd01

12:51 am on Apr 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi BobbyBudds,

I think egrophobe has the best solution, and thought maybe I could help with a little clarity on link structure.

The most important thing to remember is a link with a preceding / will start at you root (or 'home') directory, while a link without the preceding / will start from where you are and go deeper into your site, an example would be:

If your location in the browser is http//yoursite.com/stuff/page.php

"my-php/file.php" would look for this location:

http//yoursite.com/stuff/my-php/file.php
This link goes deeper into the directory you are already in.

"/my-php/file.php" would look for this location:

http//yoursite.com/my-php/file.php
This link starts at the beginning, so you actually end up at the same level in a different directory.

Not sure if you need this, but thought it might help.

Justin