note 101627 deleted from function.file-exists by danbrown

From: Date: Thu, 30 Dec 2010 20:22:42 +0000
Subject: note 101627 deleted from function.file-exists by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-175354@lists.php.net to get a copy of this message
Note Submitter: kenneth at ks81 dot com ---- Some small additions and changes to the original version by "plsnhat at gmail dot com". /** * Expanding the internal file_exists function * Searches for the file in the include_path paths. * * Test ONLY on php ver. 5.3.1 - Windows platform. **/ function fileExistsWithIncludePath( $str_filename ) { // Get the include paths. // If you want you can add a function exist check, but not necessary after php ver. 4.3.0. $str_include_path = get_include_path(); // Check if there is more than one include path in the include path. if ( FALSE !== strpos( $str_include_path, PATH_SEPARATOR ) ) { if ( FALSE !== ( $arr_temp = explode( PATH_SEPARATOR, $str_include_path ) ) && ($arr_temp_count = count( $arr_temp )) > 0 ) { for ( $int_i = 0; $int_i < $arr_temp_count; $int_i++ ) { // Check if the include path have a directory separator on the end, if not we add one. if ( preg_match( '%(?:/|\\\\)\Z%', $arr_temp[$int_i] ) ) { $str_path_and_file_name = $arr_temp[$int_i] . $str_filename; } else { $str_path_and_file_name = $arr_temp[$int_i] . DIRECTORY_SEPARATOR . $str_filename; } if ( FALSE !== @file_exists( $str_path_and_file_name ) ) { return TRUE; } } return FALSE; } else { return FALSE; } } // If there are no include path separator detected, check to see if there is one include path in the string. elseif ( !empty( $str_include_path ) ) { // Check if the include path have a directory separator on the end, if not we add one. if ( preg_match( '%(?:/|\\\\)\Z%', $str_include_path ) ) { $str_path_and_file_name = $str_include_path . $str_filename; } else { $str_path_and_file_name = $str_include_path . DIRECTORY_SEPARATOR . $str_filename; } // Check if the file exists. if ( FALSE !== @file_exists( $str_path_and_file_name ) ) { return TRUE; } else { return FALSE; } } // The include path string was empty. else { return FALSE; } }

« previous php.notes (#175354) next »