note 78716 added to function.include

From: Date: Wed, 24 Oct 2007 18:40:22 +0000
Subject: note 78716 added to function.include
Groups: php.notes 
Request: Send a blank email to php-notes+get-131696@lists.php.net to get a copy of this message
two little methods i wrote up that work on our IIS6 server. the first makes an alternate include call you can use to include things by calling them via their root location. the second method alters the include path so all include() calls are via the root location. these are a compilation of a few methods i found here, but i think i made them a bit more modular. anyhow... <?php ## MAKES A NEW FUNCTION CALLED rinclude() THAT INCLUDES ## A FILE RELATIVE TO THE ROOT DIRECTORY ## LEAVE include() UNTOUCHED SO IT CAN STILL BE USED AS NORMAL function rinclude($path){ $levels = substr_count($_SERVER['PHP_SELF'],'/'); $root = ''; for($i = 1; $i < $levels; $i++){$root .= '../';} include($root . $path); } rinclude('file.inc.php'); // in root rinclude('dir/file.inc.php'); // in a subfolder ?> <hr /> <?php ## SET INCLUDE TO ROOT DIRECTORY SO ALL include() ## CALLS WILL BE RELATIVE TO ROOT function setinclude(){ $levels = substr_count($_SERVER['PHP_SELF'],'/'); $root = ''; for($i = 1; $i < $levels; $i++){$root .= '../';} set_include_path($root); } setinclude(); include('file.inc.php'); // in root include('dir/file.inc.phpp'); // in a subfolder ?> ---- Server IP: 69.147.83.197 Probable Submitter: 72.45.168.194 ---- Manual Page -- http://www.php.net/manual/en/function.include.php Edit -- https://master.php.net/note/edit/78716 Del: integrated -- https://master.php.net/note/delete/78716/integrated Del: useless -- https://master.php.net/note/delete/78716/useless Del: bad code -- https://master.php.net/note/delete/78716/bad+code Del: spam -- https://master.php.net/note/delete/78716/spam Del: non-english -- https://master.php.net/note/delete/78716/non-english Del: in docs -- https://master.php.net/note/delete/78716/in+docs Del: other reasons-- https://master.php.net/note/delete/78716 Reject -- https://master.php.net/note/reject/78716 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131696) next »