note 101627 added to function.file-exists

From: Date: Thu, 30 Dec 2010 20:14:11 +0000
Subject: note 101627 added to function.file-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-175353@lists.php.net to get a copy of this message
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; } } ---- Server IP: 195.139.129.18 Probable Submitter: 84.48.64.87 ---- Manual Page -- http://www.php.net/manual/en/function.file-exists.php Edit -- https://master.php.net/note/edit/101627 Del: integrated -- https://master.php.net/note/delete/101627/integrated Del: useless -- https://master.php.net/note/delete/101627/useless Del: bad code -- https://master.php.net/note/delete/101627/bad+code Del: spam -- https://master.php.net/note/delete/101627/spam Del: non-english -- https://master.php.net/note/delete/101627/non-english Del: in docs -- https://master.php.net/note/delete/101627/in+docs Del: other reasons-- https://master.php.net/note/delete/101627 Reject -- https://master.php.net/note/reject/101627 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175353) next »