Moodle sending text files with incorrect text/html MIME type

Our Moodle installation was serving .txt files via file.php with an incorrect text/html MIME type instead of the correct text/plain MIME type. This was breaking the exercises from a new authoring tool we're trying out.

Adding .htaccess directives wasn't an option as the file request isn't handled by Apache. Moodle stores course files in a non-public directory, using file.php for access control.

After poking around the source code I got to line 829 of lib/filelib.php, where I saw that .txt files' MIME types are rewritten from text/plain to text/html when "filter all files" is  active. A quick visit to Administration → Modules → Filters → Manage filters and changing the "Filter uploaded files" option from "All files" to "HTML files only" fixed the issue.

This fixed the incorrect .txt MIME type

Don't forget to clear the browser's cache.

About johnny

Computers have interested me since I can remember and conveniently I studied computer science. I also enjoy performing in a local amateur theatre group and cycling. This is where I post solutions to problems I've had in the office or any other project, hopefully clearly enough to refer back to in the future.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>