Adding & removing allowed filetypes to media library in wordpress
Adding & removing allowed filetypes to the media library in WordPress
I allowed .msg file of outlook in wordpress upload media.
write this code in function.php
function my_myme_types($mime_types){
//Creating a new array will reset the allowed filetypes
$mime_types = array(
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'bmp' => 'image/bmp',
'tif|tiff' => 'image/tiff',
'msg' => 'application/vnd.ms-outlook'
);
return $mime_types;
}
add_filter('upload_mimes', 'my_myme_types', 1, 1);
Other file types:
- 'pdf' => 'application/pdf',
- 'swf' => 'application/x-shockwave-flash',
- 'mov|qt' => 'video/quicktime',
- 'flv' => 'video/x-flv',
- 'js' => 'application/javascript',
- 'avi' => 'video/avi',
- 'divx' => 'video/divx',
- 'msg' => 'application/vnd.ms-outlook',
——————————————————————————–
see other examples
function my_myme_types($mime_types){ //Adjust the $mime_types, which is an associative array where the key is extension and value is mime type. return $mime_types;}add_filter('upload_mimes', 'my_myme_types', 1, 1);
————
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);
———-
function my_myme_types($mime_types){ //Creating a new array will reset the allowed filetypes $mime_types = array( 'jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' => 'image/tiff' ); return $mime_types;}add_filter('upload_mimes', 'my_myme_types', 1, 1);
Reference:
function wp_check_filetype( $filename, $mimes = null ) {
// Accepted MIME types are set here as PCRE unless provided.
$mimes = ( is_array( $mimes ) ) ? $mimes : apply_filters( 'upload_mimes', array(
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'bmp' => 'image/bmp',
'tif|tiff' => 'image/tiff',
'ico' => 'image/x-icon',
'asf|asx|wax|wmv|wmx' => 'video/asf',
'avi' => 'video/avi',
'mov|qt' => 'video/quicktime',
'mpeg|mpg|mpe|mp4' => 'video/mpeg',
'txt|c|cc|h' => 'text/plain',
'rtx' => 'text/richtext',
'css' => 'text/css',
'htm|html' => 'text/html',
'mp3|m4a' => 'audio/mpeg',
'ra|ram' => 'audio/x-realaudio',
'wav' => 'audio/wav',
'ogg' => 'audio/ogg',
'mid|midi' => 'audio/midi',
'wma' => 'audio/wma',
'rtf' => 'application/rtf',
'js' => 'application/javascript',
'pdf' => 'application/pdf',
'doc' => 'application/msword',
'pot|pps|ppt' => 'application/vnd.ms-powerpoint',
'wri' => 'application/vnd.ms-write',
'xla|xls|xlt|xlw' => 'application/vnd.ms-excel',
'mdb' => 'application/vnd.ms-access',
'mpp' => 'application/vnd.ms-project',
'swf' => 'application/x-shockwave-flash',
'class|jar|sar|java|war|jsp' => 'application/java',
'tar' => 'application/x-tar',
'zip' => 'application/zip',
'gz|gzip' => 'application/x-gzip',
'exe' => 'application/x-msdownload',
// openoffice formats
'odt' => 'application/vnd.oasis.opendocument.text',
'odp' => 'application/vnd.oasis.opendocument.presentation',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
'odg' => 'application/vnd.oasis.opendocument.graphics',
'odc' => 'application/vnd.oasis.opendocument.chart',
'odb' => 'application/vnd.oasis.opendocument.database',
'odf' => 'application/vnd.oasis.opendocument.formula',
)
);

Post a Comment