Uploading non-media files?

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.”

Read More

Is there a way to do this using WordPress?

Related posts

Leave a Reply

3 comments

  1. 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.

  2. 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:

  3. 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.