Changeset 12165 for trunk/wp-includes/functions.php
- Timestamp:
- 11/11/2009 11:07:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r12164 r12165 2261 2261 */ 2262 2262 function wp_check_filetype( $filename, $mimes = null ) { 2263 // Accepted MIME types are set here as PCRE unless provided. 2264 $mimes = ( is_array( $mimes ) ) ? $mimes : apply_filters( 'upload_mimes', array( 2263 if ( null === $mimes ) 2264 $mimes = get_allowed_mime_types(); 2265 $type = false; 2266 $ext = false; 2267 2268 foreach ( $mimes as $ext_preg => $mime_match ) { 2269 $ext_preg = '!\.(' . $ext_preg . ')$!i'; 2270 if ( preg_match( $ext_preg, $filename, $ext_matches ) ) { 2271 $type = $mime_match; 2272 $ext = $ext_matches[1]; 2273 break; 2274 } 2275 } 2276 2277 return compact( 'ext', 'type' ); 2278 } 2279 2280 /** 2281 * Retrieve list of allowed mime types and file extensions. 2282 * 2283 * @since 2.8.6 2284 * 2285 * @return array Array of mime types keyed by the file extension regex corresponding to those types. 2286 */ 2287 function get_allowed_mime_types() { 2288 static $mimes = false; 2289 2290 if ( !$mimes ) { 2291 // Accepted MIME types are set here as PCRE unless provided. 2292 $mimes = apply_filters( 'upload_mimes', array( 2265 2293 'jpg|jpeg|jpe' => 'image/jpeg', 2266 2294 'gif' => 'image/gif', … … 2308 2336 'odb' => 'application/vnd.oasis.opendocument.database', 2309 2337 'odf' => 'application/vnd.oasis.opendocument.formula', 2310 ) 2311 ); 2312 2313 $type = false; 2314 $ext = false; 2315 2316 foreach ( $mimes as $ext_preg => $mime_match ) { 2317 $ext_preg = '!\.(' . $ext_preg . ')$!i'; 2318 if ( preg_match( $ext_preg, $filename, $ext_matches ) ) { 2319 $type = $mime_match; 2320 $ext = $ext_matches[1]; 2321 break; 2322 } 2323 } 2324 2325 return compact( 'ext', 'type' ); 2326 } 2327 2338 ) ); 2339 } 2340 2341 return $mimes; 2342 } 2328 2343 /** 2329 2344 * Retrieve nonce action "Are you sure" message.
Note: See TracChangeset
for help on using the changeset viewer.