Ticket #39552: 39552.2.diff
File 39552.2.diff, 2.2 KB (added by , 8 years ago) |
---|
-
wp-includes/functions.php
2285 2285 // Attempt to figure out what type of image it actually is 2286 2286 $real_mime = wp_get_image_mime( $file ); 2287 2287 2288 // Special-case SVG images as they may return a text/ mime-type. 2289 if ( 0 === strpos( $type, 'image/svg+xml' ) && 0 === strpos( $real_mime, 'text/' ) ) { 2290 $fhandle = fopen( $file, 'r' ); 2291 $first_five_bytes = fread( $fhandle, 5 ); 2292 fclose( $fhandle ); 2293 2294 $xmlpos = strpos( $first_five_bytes, '<?xml' ); 2295 $svgpos = strpos( $first_five_bytes, '<svg' ); 2296 if ( -1 !== $xmlpos || -1 !== $svgpos ) { 2297 $real_mime = 'image/svg+xml'; 2298 } 2299 } 2300 2288 2301 if ( ! $real_mime ) { 2289 2302 $type = $ext = false; 2290 2303 } elseif ( $real_mime != $type ) { … … 2377 2390 $mime = false; 2378 2391 } 2379 2392 2393 try { 2394 if ( false === $mime && function_exists( 'finfo_file' ) ) { 2395 // Use finfo_file if available to validate non-image files. 2396 $finfo = finfo_open( FILEINFO_MIME_TYPE ); 2397 $mime = finfo_file( $finfo, $file ); 2398 finfo_close( $finfo ); 2399 } 2400 } catch ( Exception $e ) { 2401 $mime = false; 2402 } 2403 2380 2404 return $mime; 2381 2405 } 2382 2406 … … 2408 2432 'bmp' => 'image/bmp', 2409 2433 'tiff|tif' => 'image/tiff', 2410 2434 'ico' => 'image/x-icon', 2435 'svg' => 'image/svg+xml', 2411 2436 // Video formats. 2412 2437 'asf|asx' => 'video/x-ms-asf', 2413 2438 'wmv' => 'video/x-ms-wmv', … … 2523 2548 * of file types. 2524 2549 */ 2525 2550 return apply_filters( 'ext2type', array( 2526 'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico' ),2551 'image' => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'svg' ), 2527 2552 'audio' => array( 'aac', 'ac3', 'aif', 'aiff', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ), 2528 2553 'video' => array( '3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ), 2529 2554 'document' => array( 'doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'xps', 'oxps', 'rtf', 'wp', 'wpd', 'psd', 'xcf' ),