Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.8/wp-includes/functions.php

    r12172 r11678  
    22272227 */
    22282228function wp_check_filetype( $filename, $mimes = null ) {
    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(
     2229        // Accepted MIME types are set here as PCRE unless provided.
     2230        $mimes = ( is_array( $mimes ) ) ? $mimes : apply_filters( 'upload_mimes', array(
    22592231                'jpg|jpeg|jpe' => 'image/jpeg',
    22602232                'gif' => 'image/gif',
    … …  
    23022274                'odb' => 'application/vnd.oasis.opendocument.database',
    23032275                'odf' => 'application/vnd.oasis.opendocument.formula',
    2304                 ) );
    2305         }
    2306 
    2307         return $mimes;
     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' );
    23082292}
    23092293
Note: See TracChangeset for help on using the changeset viewer.