next up previous
Next: About this document ... Up: SOW Overview Revision: 1.1.1.1 Previous: Output

dl_local

<?php
// stolen from from php.net messages
// endofyourself@yahoo.com 18-Oct-2003 04:12 
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()
?>



Mark J. Olesen 2005-01-12