Changeset 39834 for branches/4.5/src/wp-includes/functions.php
- Timestamp:
- 01/11/2017 01:14:31 PM (9 years ago)
- Location:
- branches/4.5
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/wp-includes/functions.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/4.5
-
branches/4.5/src/wp-includes/functions.php
r37286 r39834 2246 2246 * then the "proper_filename" value will be set with a proper filename and extension. 2247 2247 * 2248 * Currently this function only supports validating images known to getimagesize().2248 * Currently this function only supports renaming images validated via wp_get_image_mime(). 2249 2249 * 2250 2250 * @since 3.0.0 … … 2270 2270 } 2271 2271 2272 // We're able to validate images using GD2273 if ( $type && 0 === strpos( $type, 'image/' ) && function_exists('getimagesize')) {2272 // Validate image types. 2273 if ( $type && 0 === strpos( $type, 'image/' ) ) { 2274 2274 2275 2275 // Attempt to figure out what type of image it actually is 2276 $imgstats = @getimagesize( $file ); 2277 2278 // If getimagesize() knows what kind of image it really is and if the real MIME doesn't match the claimed MIME 2279 if ( !empty($imgstats['mime']) && $imgstats['mime'] != $type ) { 2276 $real_mime = wp_get_image_mime( $file ); 2277 2278 if ( ! $real_mime ) { 2279 $type = $ext = false; 2280 } elseif ( $real_mime != $type ) { 2280 2281 /** 2281 2282 * Filter the list mapping image mime types to their respective extensions. … … 2294 2295 2295 2296 // Replace whatever is after the last period in the filename with the correct extension 2296 if ( ! empty( $mime_to_ext[ $ imgstats['mime']] ) ) {2297 if ( ! empty( $mime_to_ext[ $real_mime ] ) ) { 2297 2298 $filename_parts = explode( '.', $filename ); 2298 2299 array_pop( $filename_parts ); 2299 $filename_parts[] = $mime_to_ext[ $ imgstats['mime']];2300 $filename_parts[] = $mime_to_ext[ $real_mime ]; 2300 2301 $new_filename = implode( '.', $filename_parts ); 2301 2302 … … 2307 2308 $ext = $wp_filetype['ext']; 2308 2309 $type = $wp_filetype['type']; 2310 } else { 2311 $type = $ext = false; 2309 2312 } 2313 } 2314 } elseif ( function_exists( 'finfo_file' ) ) { 2315 // Use finfo_file if available to validate non-image files. 2316 $finfo = finfo_open( FILEINFO_MIME_TYPE ); 2317 $real_mime = finfo_file( $finfo, $file ); 2318 finfo_close( $finfo ); 2319 2320 // If the extension does not match the file's real type, return false. 2321 if ( $real_mime !== $type ) { 2322 $type = $ext = false; 2310 2323 } 2311 2324 } … … 2324 2337 */ 2325 2338 return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes ); 2339 } 2340 2341 /** 2342 * Returns the real mime type of an image file. 2343 * 2344 * This depends on exif_imagetype() or getimagesize() to determine real mime types. 2345 * 2346 * @since 4.7.1 2347 * 2348 * @param string $file Full path to the file. 2349 * @return string|false The actual mime type or false if the type cannot be determined. 2350 */ 2351 function wp_get_image_mime( $file ) { 2352 /* 2353 * Use exif_imagetype() to check the mimetype if available or fall back to 2354 * getimagesize() if exif isn't avaialbe. If either function throws an Exception 2355 * we assume the file could not be validated. 2356 */ 2357 try { 2358 if ( ! is_callable( 'exif_imagetype' ) ) { 2359 $mime = image_type_to_mime_type( exif_imagetype( $file ) ); 2360 } elseif ( function_exists( 'getimagesize' ) ) { 2361 $imagesize = getimagesize( $file ); 2362 $mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false; 2363 } else { 2364 $mime = false; 2365 } 2366 } catch ( Exception $e ) { 2367 $mime = false; 2368 } 2369 2370 return $mime; 2326 2371 } 2327 2372
Note: See TracChangeset
for help on using the changeset viewer.