note 36130 added to function.include

From: Date: Fri, 26 Sep 2003 22:48:42 +0000
Subject: note 36130 added to function.include
Groups: php.notes 
Request: Send a blank email to php-notes+get-57184@lists.php.net to get a copy of this message
since __FILE__ works differently for different versions of PHP you dont want to write statements like <?php include(dirname(__FILE__)."/file.php"); ?> if you are going to be distributing your script. Lets say you have the directory structure home -> sites -> site2 -> www | |-->script.php |->includes |-->includeall.php |-->file1.php |-->file2.php |-->... if you want to include all of the files in the directory includes into script.php <?php //--script.php-- include_once("/home/sites/includes/includeall.php"); ?> then in includeall.php write <?php //--includeall.php-- $inc = get_included_files(); foreach($inc as $path) { $path = pathinfo($path); if($path["basename"] == "includeall.php") { define("PATH",$path["dirname"]); break; } } include_once(PATH."/file1.php"); include_once(PATH."/file2.php"); ... ?> This way you can include all of the files in the includes directory into any script by writing one include statement, and it doesn't matter what version of PHP you are useing. PATH will contain the absolute path of the includeall.php then you can just build apon that. If you have questions about this script feel free to E-Mail me I Hope this helps somebody Good Luck ---- Manual Page -- http://www.php.net/manual/en/function.include.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36130 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36130&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36130&report=yes

« previous php.notes (#57184) next »