[wp-trac] [WordPress Trac] #39963: MIME Alias Handling

WordPress Trac noreply at wordpress.org
Tue Feb 28 18:31:14 UTC 2017


#39963: MIME Alias Handling
-------------------------+------------------------------
 Reporter:  blobfolio    |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Media        |     Version:
 Severity:  normal       |  Resolution:
 Keywords:               |     Focuses:
-------------------------+------------------------------

Comment (by blobfolio):

 To get the ball rolling, here's an example of what I was thinking:
 https://github.com/Blobfolio/blob-mimes/blob/master/build/WordPress/media-
 mimes.php

 This script includes all the necessary data, and two functions.

 First, a function to return all known MIME types for a given file
 extension:

 {{{#!php
 <?php
 /**
  * Return MIME aliases for a particular file extension.
  *
  * @since xxx
  *
  * @see {https://www.iana.org/assignments/media-types}
  * @see
 {https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types}
  * @see {http://hg.nginx.org/nginx/raw-file/default/conf/mime.types}
  * @see {https://cgit.freedesktop.org/xdg/shared-mime-
 info/plain/freedesktop.org.xml.in}
  * @see {https://github.com/Blobfolio/blob-mimes}
  *
  * @param string $ext File extension.
  * @return array|bool MIME types. False on failure.
  */
 function wp_get_mime_aliases( $ext = '' ) { ... }
 }}}

 And second, a function to check whether an arbitrary file extension/MIME
 pairing is valid. This also automatically checks for both `type/subtype`
 and `type/x-subtype` variants, the `x-` prefix being something commonly
 used during a file type's transformative years, but possibly missing from
 any official database.

 {{{#!php
 <?php
 /**
  * Check extension and MIME pairing.
  *
  * @since xxx
  *
  * @param string $ext File extension.
  * @param string $mime MIME type.
  * @return bool True/false.
  */
 function wp_check_mime_alias( $ext = '', $mime = '' ) { ... }
 }}}

 This second function could be added to places like
 `wp_check_filetype_and_ext` where MIME data is pulled from somewhere
 variable (e.g. `finfo`). Rather than comparing `$real_mime` to the results
 of `wp_check_filetype()`, we can evaluate with `wp_check_mime_alias(
 $type, $real_mime )`.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39963#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list