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

Is there a way in WordPress 3.1 to restrict allowed file uploads by extension (images only) and file size?

Bonus question: Can I limit users to only be able view files they have uploaded themselves?

share|improve this question
up vote 2 down vote accepted

I believe you can add a filter to upload_mimes to restrict to certain types. The hook: http://adambrown.info/p/wp_hooks/hook/upload_mimes

The filter:


function restict_mime($mimes) { 
    $mimes = array( 
                'jpg|jpeg|jpe' => 'image/jpeg', 
                'gif' => 'image/gif', 
                'png' => 'image/png', 
    return $mimes;

From what I understand this will not work for admins or any user with the unfiltered_upload capability. Also have a look at this post Limit image upload to one and disable audio, video and other document file types to upload

An alternative to control size limit would be to use .htaccess or php.ini:

For upload limit you can set in .htaccess one of the following;

LimitRequestBody 1073741824  //( 1MB)
php_value upload_max_filesize 1M
php_value post_max_size 1M

For php.ini you can set upload_max_filesize = 1M

share|improve this answer
You're missing the following line at the end of restrict_mime function: return $mimes; – user12230 Jan 23 '12 at 8:12

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.