note 36679 added to function.dl

From: Date: Sat, 18 Oct 2003 08:12:50 +0000
Subject: note 36679 added to function.dl
Groups: php.notes 
Request: Send a blank email to php-notes+get-58801@lists.php.net to get a copy of this message
If you need to load an extension from the CURRENT local directory because you do not have privelages to place the extension in your servers PHP extensions directory, this function i wrote may be of use to you --------------- /* Function: dl_local() Reference: http://us2.php.net/manual/en/function.dl.php Author: Brendon Crawford <endofyourself |AT| yahoo> Usage: dl_local( "mylib.so" ); Returns: Extension Name (NOT the extension filename however) NOTE: This function can be used when you need to load a PHP extension (module,shared object,etc..), but you do not have sufficient privelages to place the extension in the proper directory where it can be loaded. This function will load the extension from the CURRENT WORKING DIRECTORY only. If you need to see which functions are available within a certain extension, use "get_extension_funcs()". Documentation for this can be found at "http://us2.php.net/manual/en/function.get-extension-funcs.php". */ function dl_local( $extensionFile ) { //make sure that we are ABLE to load libraries if( !(bool)ini_get( "enable_dl" ) || (bool)ini_get( "safe_mode" ) ) { die( "dh_local(): Loading extensions is not permitted.\n" ); } //check to make sure the file exists if( !file_exists( $extensionFile ) ) { die( "dl_local(): File '$extensionFile' does not exist.\n" ); } //check the file permissions if( !is_executable( $extensionFile ) ) { die( "dl_local(): File '$extensionFile' is not executable.\n" ); } //we figure out the path $currentDir = getcwd() . "/"; $currentExtPath = ini_get( "extension_dir" ); $subDirs = preg_match_all( "/\//" , $currentExtPath , $matches ); unset( $matches ); //lets make sure we extracted a valid extension path if( !(bool)$subDirs ) { die( "dl_local(): Could not determine a valid extension path [extension_dir].\n" ); } $extPathLastChar = strlen( $currentExtPath ) - 1; if( $extPathLastChar == strrpos( $currentExtPath , "/" ) ) { $subDirs--; } $backDirStr = ""; for( $i = 1; $i <= $subDirs; $i++ ) { $backDirStr .= ".."; if( $i != $subDirs ) { $backDirStr .= "/"; } } //construct the final path to load $finalExtPath = $backDirStr . $currentDir . $extensionFile; //now we execute dl() to actually load the module if( !dl( $finalExtPath ) ) { die(); } //if the module was loaded correctly, we must bow grab the module name $loadedExtensions = get_loaded_extensions(); $thisExtName = $loadedExtensions[ sizeof( $loadedExtensions ) - 1 ]; //lastly, we return the extension name return $thisExtName; }//end dl_local() ------------------------- ---- Manual Page -- http://www.php.net/manual/en/function.dl.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36679 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36679&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36679&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#58801) next »