Re: include_path and relative vs. absolute paths

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Good question. I had the same problem when i switched from .asp to .php

Suppose you want to use relative paths, eg. reference child1.php from
file1.php, where the file locations are:

  path/file1.php
  path/child/child1.php

The trick is to generate an absolute path for the current file, and find all
relative files based on this absolute path.

eg. in file1.php:

$file1AbsPath = dirname(__FILE__);
include($file1AbsPath ."/child/child1.php");



"Neil" <neil@xxxxxxxxxxx> wrote in message
news:20040817010732.57277.qmail@xxxxxxxxxxxxxxx
> I am still getting used to .php after moving from .asp and one thing I had
> trouble getting my head around was the apparent inability to use absolute
> paths for include files.
>
> If I change the include_path in php.ini to say -
> include_path=".;c:\php\site1\inc" then I can access include files either
> relatively
> eg. require '../includes/somefile.php'; where the includes folder is at
the
> same level as the current folder
> or absolutely
> eg. require 'somefile.php'; where the file is either in the same folder or
> is c:\php\site1\inc
>
> Now the second option is fine except if I have multiple sites on the one
> server.
>
> With .asp it would just read /inc/somefile.inc either from the root of the
> site or from a virtual folder but the include_path setting forces all the
> sites to use the either the one include folder or at least not use the
same
> file names if there are multiple folders specified.
>
> Does anyone know another way of dealing with this?
>
> Thanks
>
> Neil

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux