FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP and relative/absolute paths





pristine
Hi guys Very Happy

I'm very new to PHP and most of what I know covers the bare basics of variables, maybe functions and, importantly, file includes. At the moment, I am struggling to use PHP file includes, primarily because of the relative/absolute path problem.

Code:
<?php require $_SERVER[".:/usr/local/php4/share/pear"] . "/shared/banner_sub.php"; ?>


The file include works if that the main file is in the main directory. However, when I use the code for other files in sub-directories (2/3 folders down), it doesn't work. An error message comes up:

Code:
Warning: main(/shared/banner_sub.php): failed to open stream: No such file or directory in /home/www/inedit.awardspace.com/library/poetry/a_peoples_prayer_pristine_ong.php on line 16

Fatal error: main(): Failed opening required '/shared/banner_sub.php' (include_path='.:/usr/local/php4/share/pear') in /home/www/inedit.awardspace.com/library/poetry/a_peoples_prayer_pristine_ong.php on line 16


I scoured the internet and read about editing the config file, but the thing is, I can't actually find the file on my server. I know this is an old problem, but I can't seem to find the solution.

I'd appreciate any help or tips with regard to the directory issue or using config files.

Very Happy Thanks in advance Very Happy
Pristine
BlackSkad
I'm not sure because I never worked to much with absolte include-path's. But the following should work. It should do exactly the same as editting your php.ini, but it's only valid for that script. Other scripts won't have the pear-path in their include-path.

Code:
<?
ini_set('include_path',ini_get('include_path').':/usr/local/php4/share/pear/shared/:'); 
require 'banner_sub.php';
?>


Also make sure the path to your file is correct! I hope this helps...
pristine
blackskad, thanks! Very Happy
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.