[wp-trac] [WordPress Trac] #40017: wp_get_image_mime() returns 'application/octet-stream' for non-image files.

WordPress Trac noreply at wordpress.org
Thu Mar 2 18:20:31 UTC 2017


#40017: wp_get_image_mime() returns 'application/octet-stream' for non-image files.
--------------------------+-----------------------------
 Reporter:  blobfolio     |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  4.7.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 In the newly-added function `wp_get_image_mime()`, the following line
 should be split into two parts:
 {{{#!php
 <?php
 $mime = image_type_to_mime_type( exif_imagetype( $file ) );
 }}}


 `exif_imagetype()` will return `FALSE` on failure.
 `image_type_to_mime_type()` will cast `FALSE` as an integer, resulting in
 a response of "application/octet-stream" even for invalid files.

 Some EXIF types ''are'' "application/octet-stream", so to differentiate
 between failures and merely strange formats, it would be better written
 like:
 {{{#!php
 <?php
 if ( is_callable( 'exif_imagetype' ) ) {
         if ( false !== $exif_type = exif_imagetype( $file ) ) {
                 $mime = image_type_to_mime_type( $exif_type );
         } else {
                 $mime = false;
         }
 }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40017>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list