Make WordPress Core

Changeset 3894


Ignore:
Timestamp:
06/21/2006 11:17:19 PM (19 years ago)
Author:
ryan
Message:

wp_check_filetype() from skeltoac.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r3891 r3894  
    17801780        __("Failed to write file to disk."));
    17811781
    1782     // Accepted MIME types are set here as PCRE. Override with $override['mimes'].
    1783     $mimes = apply_filters('upload_mimes', array (
    1784         'jpg|jpeg|jpe' => 'image/jpeg',
    1785         'gif' => 'image/gif',
    1786         'png' => 'image/png',
    1787         'bmp' => 'image/bmp',
    1788         'tif|tiff' => 'image/tiff',
    1789         'ico' => 'image/x-icon',
    1790         'asf|asx|wax|wmv|wmx' => 'video/asf',
    1791         'avi' => 'video/avi',
    1792         'mov|qt' => 'video/quicktime',
    1793         'mpeg|mpg|mpe' => 'video/mpeg',
    1794         'txt|c|cc|h' => 'text/plain',
    1795         'rtx' => 'text/richtext',
    1796         'css' => 'text/css',
    1797         'htm|html' => 'text/html',
    1798         'mp3|mp4' => 'audio/mpeg',
    1799         'ra|ram' => 'audio/x-realaudio',
    1800         'wav' => 'audio/wav',
    1801         'ogg' => 'audio/ogg',
    1802         'mid|midi' => 'audio/midi',
    1803         'wma' => 'audio/wma',
    1804         'rtf' => 'application/rtf',
    1805         'js' => 'application/javascript',
    1806         'pdf' => 'application/pdf',
    1807         'doc' => 'application/msword',
    1808         'pot|pps|ppt' => 'application/vnd.ms-powerpoint',
    1809         'wri' => 'application/vnd.ms-write',
    1810         'xla|xls|xlt|xlw' => 'application/vnd.ms-excel',
    1811         'mdb' => 'application/vnd.ms-access',
    1812         'mpp' => 'application/vnd.ms-project',
    1813         'swf' => 'application/x-shockwave-flash',
    1814         'class' => 'application/java',
    1815         'tar' => 'application/x-tar',
    1816         'zip' => 'application/zip',
    1817         'gz|gzip' => 'application/x-gzip',
    1818         'exe' => 'application/x-msdownload'
    1819     ));
    1820 
    18211782    // All tests are on by default. Most can be turned off by $override[{test_name}] = false;
    18221783    $test_form = true;
     
    18461807        return $upload_error_handler($file, __('Specified file failed upload test.'));
    18471808
    1848     // A correct MIME type will pass this test.
     1809    // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
    18491810    if ( $test_type ) {
    1850         $type = false;
    1851         $ext = false;
    1852         foreach ($mimes as $ext_preg => $mime_match) {
    1853             $ext_preg = '![^.]\.(' . $ext_preg . ')$!i';
    1854             if ( preg_match($ext_preg, $file['name'], $ext_matches) ) {
    1855                 $type = $mime_match;
    1856                 $ext = $ext_matches[1];
    1857             }
    1858         }
     1811        $wp_filetype = wp_check_filetype($file['name'], $mimes);
     1812
     1813        extract($wp_filetype);
    18591814
    18601815        if ( !$type || !$ext )
  • trunk/wp-includes/functions.php

    r3893 r3894  
    964964function wp_upload_bits($name, $type, $bits) {
    965965    if ( empty($name) )
    966         return array('error' => "Empty filename");
     966        return array('error' => __("Empty filename"));
     967
     968    $wp_filetype = wp_check_filetype($name);
     969    if ( !$wp_filetype['ext'] )
     970        return array('error' => __("Invalid file type"));
    967971
    968972    $upload = wp_upload_dir();
     
    10101014}
    10111015
     1016function wp_check_filetype($filename, $mimes = null) {
     1017    // Accepted MIME types are set here as PCRE unless provided.
     1018    $mimes = is_array($mimes) ? $mimes : apply_filters('upload_mimes', array (
     1019        'jpg|jpeg|jpe' => 'image/jpeg',
     1020        'gif' => 'image/gif',
     1021        'png' => 'image/png',
     1022        'bmp' => 'image/bmp',
     1023        'tif|tiff' => 'image/tiff',
     1024        'ico' => 'image/x-icon',
     1025        'asf|asx|wax|wmv|wmx' => 'video/asf',
     1026        'avi' => 'video/avi',
     1027        'mov|qt' => 'video/quicktime',
     1028        'mpeg|mpg|mpe' => 'video/mpeg',
     1029        'txt|c|cc|h' => 'text/plain',
     1030        'rtx' => 'text/richtext',
     1031        'css' => 'text/css',
     1032        'htm|html' => 'text/html',
     1033        'mp3|mp4' => 'audio/mpeg',
     1034        'ra|ram' => 'audio/x-realaudio',
     1035        'wav' => 'audio/wav',
     1036        'ogg' => 'audio/ogg',
     1037        'mid|midi' => 'audio/midi',
     1038        'wma' => 'audio/wma',
     1039        'rtf' => 'application/rtf',
     1040        'js' => 'application/javascript',
     1041        'pdf' => 'application/pdf',
     1042        'doc' => 'application/msword',
     1043        'pot|pps|ppt' => 'application/vnd.ms-powerpoint',
     1044        'wri' => 'application/vnd.ms-write',
     1045        'xla|xls|xlt|xlw' => 'application/vnd.ms-excel',
     1046        'mdb' => 'application/vnd.ms-access',
     1047        'mpp' => 'application/vnd.ms-project',
     1048        'swf' => 'application/x-shockwave-flash',
     1049        'class' => 'application/java',
     1050        'tar' => 'application/x-tar',
     1051        'zip' => 'application/zip',
     1052        'gz|gzip' => 'application/x-gzip',
     1053        'exe' => 'application/x-msdownload'
     1054    ));
     1055
     1056    $type = false;
     1057    $ext = false;
     1058
     1059    foreach ($mimes as $ext_preg => $mime_match) {
     1060        $ext_preg = '!\.(' . $ext_preg . ')$!i';
     1061        if ( preg_match($ext_preg, $filename, $ext_matches) ) {
     1062            $type = $mime_match;
     1063            $ext = $ext_matches[1];
     1064            break;
     1065        }
     1066    }
     1067
     1068    return compact('ext', 'type');
     1069}
     1070
    10121071function do_trackbacks($post_id) {
    10131072    global $wpdb;
Note: See TracChangeset for help on using the changeset viewer.