{"id":154,"date":"2009-12-13T05:16:10","date_gmt":"2009-12-13T10:16:10","guid":{"rendered":"http:\/\/ebixio.com\/blog\/?p=154"},"modified":"2009-12-28T14:08:19","modified_gmt":"2009-12-28T19:08:19","slug":"adding-arbitrary-files-to-wordpress-media-library","status":"publish","type":"post","link":"http:\/\/ebixio.com\/blog\/2009\/12\/13\/adding-arbitrary-files-to-wordpress-media-library\/","title":{"rendered":"Adding arbitrary files to WordPress Media Library"},"content":{"rendered":"<p>I tried uploading a C# file to go along with a previous post, but kept getting an &#8220;IO Error&#8221; from WordPress. That wasn&#8217;t very helpful. Fortunately when I tried doing the same thing from Linux, I got a slightly more informative message telling me that the &#8220;File type does not meet security guidelines&#8221;. If you have a different idea than the developers of what constitutes a &#8220;security threat&#8221;, you can modify the list of file types that can be uploaded to WordPress. Find the <code lang=\"bash\" inline=\"on\">wp-includes\/functions.php<\/code> file in your installation directory, and add your new MIME type(s) to the default list in get_allowed_mime_types function.<\/p>\n<p>BTW, this only works if you have control over your WordPress install. If you&#8217;re using a hosted solution I guess you have to put up with it.<\/p>\n<p>This is the code you&#8217;ll want to modify:<\/p>\n\r\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/**\r\n * Retrieve list of allowed mime types and file extensions.\r\n *\r\n * @since 2.8.6\r\n *\r\n * @return array Array of mime types keyed by the file extension regex corresponding to those types.\r\n *\/\r\nfunction get_allowed_mime_types() {\r\n        static $mimes = false;\r\n\r\n        if ( !$mimes ) {\r\n                \/\/ Accepted MIME types are set here as PCRE unless provided.\r\n                $mimes = apply_filters( 'upload_mimes', array(\r\n                'jpg|jpeg|jpe' =&gt; 'image\/jpeg',\r\n                'gif' =&gt; 'image\/gif',\r\n                'png' =&gt; 'image\/png',\r\n                'bmp' =&gt; 'image\/bmp',\r\n                'tif|tiff' =&gt; 'image\/tiff',\r\n                'ico' =&gt; 'image\/x-icon',\r\n                'asf|asx|wax|wmv|wmx' =&gt; 'video\/asf',\r\n                'avi' =&gt; 'video\/avi',\r\n<\/pre>\r\n\r\n<p>If you have a lot of file types and don&#8217;t want to bother adding them all, another option is to modify your <code lang=\"bash\" inline=\"on\">wp-config.php<\/code> file and add the following line:<\/p>\n\r\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\ndefine('ALLOW_UNFILTERED_UPLOADS', true);\r\n<\/pre>","protected":false},"excerpt":{"rendered":"<p>I tried uploading a C# file to go along with a previous post, but kept getting an &#8220;IO Error&#8221; from WordPress. That wasn&#8217;t very helpful. Fortunately when I tried doing the same thing from Linux, I got a slightly more informative message telling me that the &#8220;File type does not meet security guidelines&#8221;. If you [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[26,35],"class_list":["post-154","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-security","tag-wordpress"],"_links":{"self":[{"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/comments?post=154"}],"version-history":[{"count":14,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":168,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/posts\/154\/revisions\/168"}],"wp:attachment":[{"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/media?parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/categories?post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ebixio.com\/blog\/wp-json\/wp\/v2\/tags?post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}