- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.8/wp-includes/functions.php
r11678 r12172 2227 2227 */ 2228 2228 function wp_check_filetype( $filename, $mimes = null ) { 2229 // Accepted MIME types are set here as PCRE unless provided. 2230 $mimes = ( is_array( $mimes ) ) ? $mimes : apply_filters( 'upload_mimes', array( 2229 if ( empty($mimes) ) 2230 $mimes = get_allowed_mime_types(); 2231 $type = false; 2232 $ext = false; 2233 2234 foreach ( $mimes as $ext_preg => $mime_match ) { 2235 $ext_preg = '!\.(' . $ext_preg . ')$!i'; 2236 if ( preg_match( $ext_preg, $filename, $ext_matches ) ) { 2237 $type = $mime_match; 2238 $ext = $ext_matches[1]; 2239 break; 2240 } 2241 } 2242 2243 return compact( 'ext', 'type' ); 2244 } 2245 2246 /** 2247 * Retrieve list of allowed mime types and file extensions. 2248 * 2249 * @since 2.8.6 2250 * 2251 * @return array Array of mime types keyed by the file extension regex corresponding to those types. 2252 */ 2253 function get_allowed_mime_types() { 2254 static $mimes = false; 2255 2256 if ( !$mimes ) { 2257 // Accepted MIME types are set here as PCRE unless provided. 2258 $mimes = apply_filters( 'upload_mimes', array( 2231 2259 'jpg|jpeg|jpe' => 'image/jpeg', 2232 2260 'gif' => 'image/gif', … … 2274 2302 'odb' => 'application/vnd.oasis.opendocument.database', 2275 2303 'odf' => 'application/vnd.oasis.opendocument.formula', 2276 ) 2277 ); 2278 2279 $type = false; 2280 $ext = false; 2281 2282 foreach ( $mimes as $ext_preg => $mime_match ) { 2283 $ext_preg = '!\.(' . $ext_preg . ')$!i'; 2284 if ( preg_match( $ext_preg, $filename, $ext_matches ) ) { 2285 $type = $mime_match; 2286 $ext = $ext_matches[1]; 2287 break; 2288 } 2289 } 2290 2291 return compact( 'ext', 'type' ); 2304 ) ); 2305 } 2306 2307 return $mimes; 2292 2308 } 2293 2309
Note: See TracChangeset
for help on using the changeset viewer.