Re: include path

From: Date: Thu, 30 Nov 2000 01:11:13 +0000
Subject: Re: include path
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-27952@lists.php.net to get a copy of this message
Hey Folks: Dan Lowe wrote: > > There's a problem with that though - if you have /a/subdir/file.php > and it contains: > > include('../main.php'); > > That works fine to include main.php. But if main.php contains: > > include('another_file.php'); > > Then it can't find "another_file.php" to include. It lives in /a but your > script is really looking in /a/subdir so it can't find it. That's exactly what I said. Paths are relative to the page you start from. So, in this case, you'd have to write your code in main.php to say include('../another_file.php'); But, if you're calling main.php from lots of different directories and sub directories, you'll have problems. Actually, what always do is use a variable of where to find the include files. I set it in the main file and then all subsequent requests look in the right place. include("$IncludeDir/main.php"); include("$IncludeDir/another_file.php"); Enjoy, --Dan -- PHP scripts that make your job easier http://www.analysisandsolutions.com/code/ SQL Solution | Layout Solution | Form Solution T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Ave, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409

« previous php.general (#27952) next »