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 am trying to include the new WP Media Uploader in a Custom Meta Box.

I found this tutorial:

http://codestag.com/how-to-use-wordpress-3-5-media-uploader-in-theme-options/

However i am looking for a way to limit the uploader to only accept certain types of files like 'application/msword', 'application/vnd.ms-excel', 'application/pdf', etc. and to return the linked document url to a text field i have in the metabox

I have searched google now for countless hours but could not find anything useful...

Any ideas, links or just basically anything to point me in the right direction would be highly appreciated!

Thanks!

share|improve this question
    
add comment

2 Answers

The file types that you have specified 'application/msword', 'application/vnd.ms-excel', 'application/pdf' are already supported by media uploader.

To see the default supported mime file types, call wp_get_mime_types() function.

Use upload_mimes filter as shown in following code to make media uploader to accept files types other than the default.

Add following code in your themes functions.php file

// Add the filter
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['prc'] = 'application/x-mobipocket'; 

// and return the new full result
return $existing_mimes; 
}
share|improve this answer
    
thanks, but how do i limit the mime types to only the selected mime types for that specific instance of the media upload? I don't want to limit the standard WP Editor upload to those same mime types... –  tiaanswart Apr 12 '13 at 6:54
add comment

Like Vinod Dalvi said, you could use the filter upload_mimes to achieve what you need. You can deregister existing mimes types using

unset($mime_types['pdf']);

and adding new type by adding then to the array :

$mime_types['avi'] = 'video/avi';

for instance

function my_myme_types($mime_types){
    $mime_types['avi'] = 'video/avi'; //Adding avi extension
    unset($mime_types['pdf']); //Removing the pdf extension
    return $mime_types;
}
add_filter('upload_mimes', 'my_myme_types', 1, 1);

This is taken from here

You say :

how do i limit the mime types to only the selected mime types for that specific instance of the media upload? I don't want to limit the standard WP Editor upload to those same mime types

Do you mean limiting mime type only for one type of uploader ? I can't see the logic involved, since if there are other "instances" of media uploader, "forbidden" media types could be uploaded anyway.

share|improve this answer
add comment

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.