WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to upload java files to my word press blog but it does not let me upload any files with .java extension.

It says ".java” has failed to upload due to an error *File type does not meet security guidelines. Try another.*

So how do I add .java extension so that it allows me to upload java source code.

I am using wordpress version 3.0.4.


share|improve this question
up vote 3 down vote accepted

Use filter 'upload_mimes'.


function add_java_files($mimes)
    // Add file extension 'extension' with mime type 'mime/type'
    $mimes['java'] = 'text/x-java-source';
    return $mimes;
share|improve this answer

I found this nice function that does the trick

function addUploadMimes($mimes) {
    $mimes = array_merge($mimes, array(
        'tmbundle|tmCommand|tmDragCommand|tmSnippet|tmLanguage|tmPreferences' => 'application/octet-stream'
    return $mimes;
add_filter('upload_mimes', 'addUploadMimes');

you can add more file types by adding them on "'tmbundle|tmCommand|tmDragCommand|tmSnippet|tmLanguage|tmPreferences'"

separated by a pipe (|)

share|improve this answer

Your Answer


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.