Changeset 39842 for branches/3.7/src
- Timestamp:
- 01/11/2017 01:21:01 PM (8 years ago)
- Location:
- branches/3.7
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.7
-
branches/3.7/src
- Property svn:mergeinfo changed
/trunk/src merged: 39831
- Property svn:mergeinfo changed
-
branches/3.7/src/wp-includes/functions.php
r27887 r39842 1879 1879 * then the "proper_filename" value will be set with a proper filename and extension. 1880 1880 * 1881 * Currently this function only supports validating images known to getimagesize().1881 * Currently this function only supports renaming images validated via wp_get_image_mime(). 1882 1882 * 1883 1883 * @since 3.0.0 … … 1900 1900 return compact( 'ext', 'type', 'proper_filename' ); 1901 1901 1902 // We're able to validate images using GD1903 if ( $type && 0 === strpos( $type, 'image/' ) && function_exists('getimagesize')) {1902 // Validate image types. 1903 if ( $type && 0 === strpos( $type, 'image/' ) ) { 1904 1904 1905 1905 // Attempt to figure out what type of image it actually is 1906 $imgstats = @getimagesize( $file ); 1907 1908 // If getimagesize() knows what kind of image it really is and if the real MIME doesn't match the claimed MIME 1909 if ( !empty($imgstats['mime']) && $imgstats['mime'] != $type ) { 1906 $real_mime = wp_get_image_mime( $file ); 1907 1908 if ( ! $real_mime ) { 1909 $type = $ext = false; 1910 } elseif ( $real_mime != $type ) { 1910 1911 // This is a simplified array of MIMEs that getimagesize() can detect and their extensions 1911 1912 // You shouldn't need to use this filter, but it's here just in case … … 1919 1920 1920 1921 // Replace whatever is after the last period in the filename with the correct extension 1921 if ( ! empty( $mime_to_ext[ $ imgstats['mime']] ) ) {1922 if ( ! empty( $mime_to_ext[ $real_mime ] ) ) { 1922 1923 $filename_parts = explode( '.', $filename ); 1923 1924 array_pop( $filename_parts ); 1924 $filename_parts[] = $mime_to_ext[ $ imgstats['mime']];1925 $filename_parts[] = $mime_to_ext[ $real_mime ]; 1925 1926 $new_filename = implode( '.', $filename_parts ); 1926 1927 … … 1931 1932 $wp_filetype = wp_check_filetype( $new_filename, $mimes ); 1932 1933 extract( $wp_filetype ); 1934 } else { 1935 $type = $ext = false; 1933 1936 } 1937 } 1938 } elseif ( function_exists( 'finfo_file' ) ) { 1939 // Use finfo_file if available to validate non-image files. 1940 $finfo = finfo_open( FILEINFO_MIME_TYPE ); 1941 $real_mime = finfo_file( $finfo, $file ); 1942 finfo_close( $finfo ); 1943 1944 // If the extension does not match the file's real type, return false. 1945 if ( $real_mime !== $type ) { 1946 $type = $ext = false; 1934 1947 } 1935 1948 } … … 1938 1951 // Should return an array in the style of array( 'ext' => $ext, 'type' => $type, 'proper_filename' => $proper_filename ) 1939 1952 return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes ); 1953 } 1954 1955 /** 1956 * Returns the real mime type of an image file. 1957 * 1958 * This depends on exif_imagetype() or getimagesize() to determine real mime types. 1959 * 1960 * @since 4.7.1 1961 * 1962 * @param string $file Full path to the file. 1963 * @return string|false The actual mime type or false if the type cannot be determined. 1964 */ 1965 function wp_get_image_mime( $file ) { 1966 /* 1967 * Use exif_imagetype() to check the mimetype if available or fall back to 1968 * getimagesize() if exif isn't avaialbe. If either function throws an Exception 1969 * we assume the file could not be validated. 1970 */ 1971 try { 1972 if ( ! is_callable( 'exif_imagetype' ) ) { 1973 $mime = image_type_to_mime_type( exif_imagetype( $file ) ); 1974 } elseif ( function_exists( 'getimagesize' ) ) { 1975 $imagesize = getimagesize( $file ); 1976 $mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false; 1977 } else { 1978 $mime = false; 1979 } 1980 } catch ( Exception $e ) { 1981 $mime = false; 1982 } 1983 1984 return $mime; 1940 1985 } 1941 1986
Note: See TracChangeset
for help on using the changeset viewer.