2
votes

I would like to upload a code file to wordpress so that people can download it from my website. However, when I try to upload, it gives me this error:

sorry this file type is not permitted for security reasons

I am trying to upload a .m file to my website. Need some guidance on how to solve this issue.

1
I believe wordpress only allows image files, but some forum posts mention this plugin may help you: wordpress.org/plugins/gd-bbpress-attachmentsadmdrew
tried this. not working for me.lakesh

1 Answers

3
votes

The Codex explains here how you can change the allowed mime types, through the upload_mimes filter.

If you mean a Matlab file with the .m extension, then you could try the following plugin:

<?php

/**
 * Plugin Name: Support Matlab (.m) uploads
 * Description: Support uploads of Matlab .m files.
 * Plugin URI:  http://stackoverflow.com/a/27785139/2078474
 * Author:      birgire, Codex
 * Version:     0.0.1
 */

add_filter('upload_mimes', 'custom_upload_mimes' );

function custom_upload_mimes ( $existing_mimes = array() )
{ 
    // Add file extension 'extension' with mime type 'mime/type'
    // $existing_mimes['extension'] = 'mime/type';

    // ----------------------
    // Your modifications:
    // Support for .m files:
    $existing_mimes['m'] = 'application/matlab';
    // ----------------------

    return $existing_mimes;
}

where you might have to adjust the mime part to your needs.