WordPress增加后台可以上传的文件格式

以下允许了 “.css”文件的上传。
function my_myme_types($mime_types){
    $mime_types['css'] = 'text/css'; //Adding css extension
    return $mime_types;
}
add_filter('upload_mimes', 'my_myme_types', 1, 1);
阻止某些格式的文件上传

add_filter(‘upload_mimes’, ‘custom_upload_mimes’);
function custom_upload_mimes ( $existing_mimes=array() ) {
unset( $existing_mimes[‘exe’] );
// add as many as you like
// and return the new full result
return $existing_mimes;
}

当然也可以用插件来解决:Wp Extra File Types,使用这个插件,比如如果自定义可以上传css文件,MIME设置为“text/css”时,有些服务器会提到 “因为安全问题,阻止了这个文件的上传”,此时可以修改设置为“text/plain”.

来源:How to Add Additional File Types to be Uploaded in WordPress

支持 dwg 格式文件上传

function custom_upload_mimes ( $existing_mimes=array() ) {
    $existing_mimes['dwg'] = 'image/vnd.dwg';
    return $existing_mimes;
}
add_filter('upload_mimes', 'custom_upload_mimes');

常见文件的mime:
https://www.w3school.com.cn/media/media_mimeref.asp

 2,052 total views,  2 views today

Revisions

There are no revisions for this post.

Comments are closed.