You are here: Re: Relative paths in require_once problem (possibly all include routines) « PHP Programming Language « IT news, forums, messages
Re: Relative paths in require_once problem (possibly all include routines)

Posted by Steve on 01/03/08 15:13

> mmmm, path dependency...
>
> So, what do you recommend instead, then, that wouldn't use
> document_root? Saying 'switch hosts' doesn't help much, as it's not
> gonna happen.

that's about all you're going to get from jerry. :)

i'll repost this:

<?
$parsedUri = dirname($_SERVER['PHP_SELF']);
$parsedUri .= substr($parsedUri, -1) != '/' ? '/' : '';
$relativeUri = str_replace('/', '', $parsedUri);
$relativePath = strlen($parsedUri) - strlen($relativeUri) - 1;
if ($relativePath < 0){ $relativePath = 0; }
$relativePath = str_repeat('../', $relativePath);
if (!$relativePath){ $relativePath = './'; }
?>

name that whatever you will...say, relative.path.php, for instance. put that
script in your php include_path. from there, it doesn't matter where your
parent script is run. you get document_root in relative terms regardless of
what your server's configuration is. to implement this, just do this at the
top of your parent script:

<?
require_once 'relative.path.php';
include_once $relativePath . 'name of other script to include here';
// rest of code
?>

hth,

me

 

Navigation:

[Reply to this 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

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