Changeset 3895
- Timestamp:
- 06/21/2006 11:24:13 PM (18 years ago)
- Location:
- branches/2.0
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0/wp-admin/admin-functions.php
r3892 r3895 1665 1665 __("Failed to write file to disk.")); 1666 1666 1667 // Accepted MIME types are set here as PCRE. Override with $override['mimes'].1668 $mimes = apply_filters('upload_mimes', array (1669 'jpg|jpeg|jpe' => 'image/jpeg',1670 'gif' => 'image/gif',1671 'png' => 'image/png',1672 'bmp' => 'image/bmp',1673 'tif|tiff' => 'image/tiff',1674 'ico' => 'image/x-icon',1675 'asf|asx|wax|wmv|wmx' => 'video/asf',1676 'avi' => 'video/avi',1677 'mov|qt' => 'video/quicktime',1678 'mpeg|mpg|mpe' => 'video/mpeg',1679 'txt|c|cc|h' => 'text/plain',1680 'rtx' => 'text/richtext',1681 'css' => 'text/css',1682 'htm|html' => 'text/html',1683 'mp3|mp4' => 'audio/mpeg',1684 'ra|ram' => 'audio/x-realaudio',1685 'wav' => 'audio/wav',1686 'ogg' => 'audio/ogg',1687 'mid|midi' => 'audio/midi',1688 'wma' => 'audio/wma',1689 'rtf' => 'application/rtf',1690 'js' => 'application/javascript',1691 'pdf' => 'application/pdf',1692 'doc' => 'application/msword',1693 'pot|pps|ppt' => 'application/vnd.ms-powerpoint',1694 'wri' => 'application/vnd.ms-write',1695 'xla|xls|xlt|xlw' => 'application/vnd.ms-excel',1696 'mdb' => 'application/vnd.ms-access',1697 'mpp' => 'application/vnd.ms-project',1698 'swf' => 'application/x-shockwave-flash',1699 'class' => 'application/java',1700 'tar' => 'application/x-tar',1701 'zip' => 'application/zip',1702 'gz|gzip' => 'application/x-gzip',1703 'exe' => 'application/x-msdownload'1704 ));1705 1706 1667 // All tests are on by default. Most can be turned off by $override[{test_name}] = false; 1707 1668 $test_form = true; … … 1731 1692 return $upload_error_handler($file, __('Specified file failed upload test.')); 1732 1693 1733 // A correct MIME type will pass this test. 1694 // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter. 1734 1695 if ( $test_type ) { 1735 $type = false; 1736 $ext = false; 1737 foreach ($mimes as $ext_preg => $mime_match) { 1738 $ext_preg = '![^.]\.(' . $ext_preg . ')$!i'; 1739 if ( preg_match($ext_preg, $file['name'], $ext_matches) ) { 1740 $type = $mime_match; 1741 $ext = $ext_matches[1]; 1742 } 1743 } 1696 $wp_filetype = wp_check_filetype($file['name'], $mimes); 1697 1698 extract($wp_filetype); 1744 1699 1745 1700 if ( !$type || !$ext ) -
branches/2.0/wp-includes/functions-post.php
r3762 r3895 918 918 function wp_upload_bits($name, $type, $bits) { 919 919 if ( empty($name) ) 920 return array('error' => "Empty filename"); 920 return array('error' => __("Empty filename")); 921 922 $wp_filetype = wp_check_filetype($name); 923 if ( !$wp_filetype['ext'] ) 924 return array('error' => __("Invalid file type")); 921 925 922 926 $upload = wp_upload_dir(); … … 964 968 } 965 969 970 function wp_check_filetype($filename, $mimes = null) { 971 // Accepted MIME types are set here as PCRE unless provided. 972 $mimes = is_array($mimes) ? $mimes : apply_filters('upload_mimes', array ( 973 'jpg|jpeg|jpe' => 'image/jpeg', 974 'gif' => 'image/gif', 975 'png' => 'image/png', 976 'bmp' => 'image/bmp', 977 'tif|tiff' => 'image/tiff', 978 'ico' => 'image/x-icon', 979 'asf|asx|wax|wmv|wmx' => 'video/asf', 980 'avi' => 'video/avi', 981 'mov|qt' => 'video/quicktime', 982 'mpeg|mpg|mpe' => 'video/mpeg', 983 'txt|c|cc|h' => 'text/plain', 984 'rtx' => 'text/richtext', 985 'css' => 'text/css', 986 'htm|html' => 'text/html', 987 'mp3|mp4' => 'audio/mpeg', 988 'ra|ram' => 'audio/x-realaudio', 989 'wav' => 'audio/wav', 990 'ogg' => 'audio/ogg', 991 'mid|midi' => 'audio/midi', 992 'wma' => 'audio/wma', 993 'rtf' => 'application/rtf', 994 'js' => 'application/javascript', 995 'pdf' => 'application/pdf', 996 'doc' => 'application/msword', 997 'pot|pps|ppt' => 'application/vnd.ms-powerpoint', 998 'wri' => 'application/vnd.ms-write', 999 'xla|xls|xlt|xlw' => 'application/vnd.ms-excel', 1000 'mdb' => 'application/vnd.ms-access', 1001 'mpp' => 'application/vnd.ms-project', 1002 'swf' => 'application/x-shockwave-flash', 1003 'class' => 'application/java', 1004 'tar' => 'application/x-tar', 1005 'zip' => 'application/zip', 1006 'gz|gzip' => 'application/x-gzip', 1007 'exe' => 'application/x-msdownload' 1008 )); 1009 1010 $type = false; 1011 $ext = false; 1012 1013 foreach ($mimes as $ext_preg => $mime_match) { 1014 $ext_preg = '!\.(' . $ext_preg . ')$!i'; 1015 if ( preg_match($ext_preg, $filename, $ext_matches) ) { 1016 $type = $mime_match; 1017 $ext = $ext_matches[1]; 1018 break; 1019 } 1020 } 1021 1022 return compact('ext', 'type'); 1023 } 1024 966 1025 ?>
Note: See TracChangeset
for help on using the changeset viewer.