一个资源分享、信息整合的综合性站点。

标题: wordpress如何自定义上传文件类型? [打印本页]

作者: 树苗收集系    时间: 2019-11-26 23:49
标题: wordpress如何自定义上传文件类型?
众所周知WordPress默认支持大部分图片等文件格式的上传,但也有一些文件格式是不支持的,根据个人需要,我们需要增加一些格式,一些格式也可以禁止上传,设置非常非常简单,下面来一起看看吧。

方法如下:

直接把以下代码复制到你的主题的functions.php文件中,如果没有这个文件,就新建一个。
  1. add_filter(‘upload_mimes’, ‘custom_upload_mimes’);
  2. function custom_upload_mimes ( $existing_mimes=array() ) {
  3. // 添加支持上传的文件类型
  4. $existing_mimes['zip'] = ‘application/zip’;
  5. // 可以添加其他类型,注意换行
  6. // 下载是禁止上传的文件类型
  7. unset( $existing_mimes['exe'] );
  8. unset( $existing_mimes['php'] );
  9. unset( $existing_mimes['asp'] );
  10. unset( $existing_mimes['bat'] );
  11. // 可以添加多种类型,注意换行
  12. return $existing_mimes;
  13. }
复制代码
这段代码就是允许上传zip文件格式,同时禁止exe/php/asp/bat文件格式的上传,其他格式以次类推,够方便吧?







欢迎光临 一个资源分享、信息整合的综合性站点。 (https://www.sorv.cn/) Powered by Discuz! X3.4