WordPress默认支持大部分图片等文件格式的上传,但也有一些文件格式是不支持的,根据个人需要,我们需要增加一些格式,一些格式也可以禁止上传,设置非常非常简单,方法如下:,直接把以下代码复制到你的主题的functions.php文件中,如果没有这个文件,就新建一个。,add_filter(‘upload_mimes’, ‘custom_upload_mimes’);
function custom_upload_mimes ( $existing_mimes=array() ) {
// 添加支持上传的文件类型
$existing_mimes['zip'] = ‘application/zip’;
// 可以添加其他类型,注意换行
// 下载是禁止上传的文件类型
unset( $existing_mimes['exe'] );
unset( $existing_mimes['php'] );
unset( $existing_mimes['asp'] );
unset( $existing_mimes['bat'] );
// 可以添加多种类型,注意换行
return $existing_mimes;
},这段代码就是允许上传zip文件格式,同时禁止exe/php/asp/bat文件格式的上传,其他格式以次类推,够方便吧?,

WordPress默认支持大部分图片等文件格式的上传,但也有一些文件格式是不支持的,根据个人需要,我们需要增加一些格式,一些格式也可以禁止上传,设置非常非常简单,方法如下:

直接把以下代码复制到你的主题的functions.php文件中,如果没有这个文件,就新建一个。

add_filter(‘upload_mimes’, ‘custom_upload_mimes’);
function custom_upload_mimes ( $existing_mimes=array() ) {
// 添加支持上传的文件类型
$existing_mimes['zip'] = ‘application/zip’;
// 可以添加其他类型,注意换行
// 下载是禁止上传的文件类型
unset( $existing_mimes['exe'] );
unset( $existing_mimes['php'] );
unset( $existing_mimes['asp'] );
unset( $existing_mimes['bat'] );
// 可以添加多种类型,注意换行
return $existing_mimes;
}

这段代码就是允许上传zip文件格式,同时禁止exe/php/asp/bat文件格式的上传,其他格式以次类推,够方便吧?

,

WordPress默认支持大部分图片等文件格式的上传,但也有一些文件格式是不支持的,根据个人需要,我们需要增加一些格式,一些格式也可以禁止上传,设置非常非常简单,方法如下:

直接把以下代码复制到你的主题的functions.php文件中,如果没有这个文件,就新建一个。

add_filter(‘upload_mimes’, ‘custom_upload_mimes’);
function custom_upload_mimes ( $existing_mimes=array() ) {
// 添加支持上传的文件类型
$existing_mimes['zip'] = ‘application/zip’;
// 可以添加其他类型,注意换行
// 下载是禁止上传的文件类型
unset( $existing_mimes['exe'] );
unset( $existing_mimes['php'] );
unset( $existing_mimes['asp'] );
unset( $existing_mimes['bat'] );
// 可以添加多种类型,注意换行
return $existing_mimes;
}

这段代码就是允许上传zip文件格式,同时禁止exe/php/asp/bat文件格式的上传,其他格式以次类推,够方便吧?

最后修改:2025 年 09 月 10 日
如果觉得我的文章对你有用,请随意夸赞