Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to add files on WordPress that are non images, embedded video and the like. However when I try this using the upload media feature I get the following error.

"File type does not meet security guidelines."

Is there a way to do this using WordPress?

share|improve this question

3 Answers 3

There are two ways that error can be triggered ( source ):

  • user does not have unfiltered_upload capability;

  • WP does not like file type or extension.

Latter is checked by wp_check_filetype_and_ext() function ( source ) that filters return through wp_check_filetype_and_ext hook to allow validation of additional file types.

share|improve this answer
    
I am the site admin, so that is not really a problem. But how can I allow other types of media files? Is there way to disable those filter functions? –  Bryan Harrington Feb 14 '11 at 18:30
1  
@Bryan Harrington sorry, I had not worked with uploads at all and don't have clear idea about implementing custom validation. Quick search through usual resources got me this -allow upload of more file types. –  Rarst Feb 14 '11 at 18:47

Extending @Rarst Answer, I've tried the filter wp_check_filetype_and_ext and this is how it can be used to allow PHP file types:

add_filter( 'wp_check_filetype_and_ext', 'file_and_ext_wpse_9289', 10, 4 );

function file_and_ext_wpse_9289( $types, $file, $filename, $mimes )
{
    if( false !== strpos( $filename, '.php' ) )
    {
        $types['ext'] = 'php';
        $types['type'] = 'text/x-php';
    }
    return $types;
}

However, the easiest way is using the filter upload_mimes:

share|improve this answer

I got the same error when I was trying to upload .java source files.

Use your favorite text editor and open file wp-includes/functions.php.
Search for 'mpeg', the second occurrence will get you inside a function called get_allowed_mime_types.
I added 'java' to the line that had 'txt|asc|c|cc|h'. Now the file upload is working fine for .java files.

share|improve this answer
1  
It's not a good idea to update core files (like those in the wp-includes directory). Any future updates to WordPress may overwrite your changes. You're far better to use the robust filter system to modify how WordPress works -- in this case, you can add a filter to upload_mimes. –  Pat J Apr 10 '13 at 21:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.