[wp-trac] [WordPress Trac] #46903: Uploading .txt file fails due to 'fileinfo' extension thinking it's a file with MIME type 'text/html' instead of 'text/plain'

WordPress Trac noreply at wordpress.org
Fri Apr 12 22:01:20 UTC 2019

#46903: Uploading .txt file fails due to 'fileinfo' extension thinking it's a file
with MIME type 'text/html' instead of 'text/plain'
 Reporter:  renstillmann  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  5.1.1
 Severity:  blocker       |   Keywords:  dev-feedback
  Focuses:                |

 I build a plugin which exports and imports settings and saves it to a
 .html file.
 However the contents of this .txt file might or might not contain some
 HTML tags. This becomes an issue when it contains HTML tags when trying to
 upload the .txt file because in this case WordPress thinks the MIME type
 is 'text/html' while it really is 'text/plain'. WordPress throws an error
 stating that the file extension can't be uploaded due to security reasons.
 (understandable because it checks if 'text/html' == 'text/plain' which
 obviously isn't going to be the case. This info is returned by the
 'finfo_file()' when extension 'fileinfo' is being used.

 So now I thought it would be a good idea to just instead use the .html
 extension instead, but now the opposite is happening as soon as the .html
 file doesn't actually contain any html tags. Now wordpress thinks it's
 MIME type is 'text/plain' and again fails because due to the comparison of
 the .html file extension to the 'text/html' MIME type.

 I did some debugging on this and found out about an array that was created
 for the same kind of problem with uploading other file types (csv,
 richtext, tsv, vtt).

 In functions.php on line 2590 an array exists with "// A few common file
 types are occasionally detected as text/plain; allow those", it is missing
 a value for the 'text/html' mime type. As soon as I add this I can upload
 the .html file (even when it doesn't contain any HTML tags) without

 Perhaps I am not aware of some other file extension that I really should
 be using?
 The export/import file contains a serialized string with all settings. The
 settings may or may not contain HTML tags. It really doesn't care what
 file extension I use as long as it can be uploaded without issues to the
 Media library.

 Hope someone can help me with this problem I am facing, thanks!

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

More information about the wp-trac mailing list