Reply to Re: Relative paths and include files

Your name:

Reply:


Posted by Tex John on 07/19/05 21:46

I store all my includes outside of the web in their own directory or
directories. Where you have the index.php, I have an include file that is
just a quickie config file setting the absolute path to the main include
directory. Then I can use subdirectories in the web pages that pull the
includes.

Say I want to include this header:

/www/somesite/php/includes/bluetemplate/header.inc.php

in this index file:

/www/somesite/htmldocs/index.php

Then I would have this config file define the absolute path:

/www/somesite/htmldocs/config.inc.php -> $inc_dir =
"/www/somesite/php/includes/";

And in index.php say this:

require_once("config.inc.php");
include_once( $inc_dir . "bluetemplate/header.inc.php");

The way I work, I'd probably define a template variable in config.inc.php,
too, because I'm so lazy:

require_once("config.inc.php");
include_once( $inc_dir . $template_name . "header.inc.php");

Just make sure you are consistent with when you include slashed and don't
and you are good to go.

hth,
John

"mark" <mark@something.com> wrote in message
news:dber1t$j9d$1@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
> I am designing a website at the moment and looking at the difference
> between relative and absolute url links which is driving me crazy! I
> would like to use relative paths, but it is proving very restrictive as
> to how I design the file structure when it comes to including files. I
> currently have something like below:
>
> folder1
> folder2
> images
> ---image1.gif
> includes
> ---header.php
> ---footer.php
> folder3
> ---folder4
> ---file0.php
> ---file1.php
> ---file2.php
> index.php
>
>
> I am currently thinking I will have to run all my scripts at the same
> level to ensure I can include the header.php file in all my pages while
> maintaining the integrity of links in the header.php. For example, if I
> include header.php in index.php and header.php is referencing
> ../images/image1.gif in the images folder, the link will no longer be
> valid when included in index.php. Does that make sense?
>
> Can anybody share some tips on what they do to overcome what must be a
> very common problem? Is absolute paths the answer so instead of calling
> ../images/image.gif from the include file, I would call
/images/image1.gif?
>
> Any help that anybody can give me would be much appreciated.
>
> Thanks,
> Mark.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация