[wp-trac] [WordPress Trac] #45615: CSV Mime Type fails upload
WordPress Trac
noreply at wordpress.org
Tue Dec 25 13:58:10 UTC 2018
#45615: CSV Mime Type fails upload
--------------------------------------+------------------------
Reporter: Kloon | Owner: joemcgill
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 5.0.3
Component: Upload | Version: 5.0.1
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses:
--------------------------------------+------------------------
Comment (by birgire):
As I understand it:
If we associate a given file extension to multiple mime types in
{{{wp_get_mime_types()}}}, then {{{wp_check_filetype()}}} will only pick
up the first match, because of the break in the foreach loop when a match
is confirmed ([https://core.trac.wordpress.org/browser/tags/5.0/src/wp-
includes/functions.php#L2262 src]).
So having e.g.
{{{
'txt|asc|c|cc|h|srt|vtt' => 'text/plain',
}}}
before
{{{
'vtt' => 'text/vtt',
}}}
will mean that the {{{.vtt}}} file type will only be expected to have the
{{{text/plain}}} mime type, regardless of other possible matches.
It also seems that {{{file_info()}}} is not consistent determining the
real mime type info depending on the system setup.
So simply assigning a file extension to multiple mime types in
{{{wp_get_mime_types()}}} will not solve the issue here. An actual support
for multiple mime types or mime type "fallbacks" seems to be needed.
----
In the meanwhile here's a suggestion for a plugin workaround to support a
fallback mime type of a given file extension:
{{{
/**
* Support for 'text/plain' as the secondary mime type of .vtt files,
* in addition to the default 'text/vtt' support.
*/
add_filter( 'wp_check_filetype_and_ext', 'wpse323750_secondary_mime', 99,
4 );
function wpse323750_secondary_mime( $check, $file, $filename, $mimes ) {
if ( empty( $check['ext'] ) && empty( $check['type'] ) ) {
// Adjust to your needs!
$secondary_mime = [ 'vtt' => 'text/plain' ];
// Run another check, but only for our secondary mime and not on
core mime types.
remove_filter( 'wp_check_filetype_and_ext',
'wpse323750_secondary_mime', 99, 4 );
$check = wp_check_filetype_and_ext( $file, $filename,
$secondary_mime );
add_filter( 'wp_check_filetype_and_ext',
'wpse323750_secondary_mime', 99, 4 );
}
return $check;
}
}}}
and it's possible to extend this further for multiple fallbacks, see
[https://wordpress.stackexchange.com/a/323757/26350 here].
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45615#comment:27>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list