禁止wordpress用户上传一些特定后缀的文件,和修改文件上传容量限制

不管从安全考虑还是说从网站流量等考虑,限制用户上传一些特定后缀比如exe还是很有必要的。干货方法,在当前主题的functions添加如下代码:

  1. add_filter(‘upload_mimes’, ‘custom_upload_mimes’);
  2. function custom_upload_mimes( $existing_mimes=array() ) {
  3.   // 注意中括号中的名称,必须取自上面支持列表中中括号的名称
  4.   unset( $existing_mimes[‘exe’] ); //此处禁止了上传exe后缀名的可运行文件

unset( $existing_mimes[‘htm|html’] ); //此处禁止了上传html和htm后缀名的压缩文件

  1.   return $existing_mimes;
  2. }

如果还想禁止其他后缀文件,请参考下列表

  1. [jpg|jpeg|jpe] => image/jpeg
  2.     [gif] => image/gif
  3.     [png] => image/png
  4.     [bmp] => image/bmp
  5.     [tif|tiff] => image/tiff
  6.     [ico] => image/x-icon
  7.     [asf|asx|wax|wmv|wmx] => video/asf
  8.     [avi] => video/avi
  9.     [divx] => video/divx
  10.   [flv] => video/x-flv
  11.   [mov|qt] => video/quicktime
  12.   [mpeg|mpg|mpe] => video/mpeg
  13.   [mp4|m4v] => video/mp4
  14.   [ogv] => video/ogg
  15.   [mkv] => video/x-matroska
  16.   [txt|asc|c|cc|h] => text/plain
  17.   [csv] => text/csv
  18.   [tsv] => text/tab-separated-values
  19.   [ics] => text/calendar
  20.   [rtx] => text/richtext
  21.   [css] => text/css
  22.   [htm|html] => text/html
  23.   [mp3|m4a|m4b] => audio/mpeg
  24.   [ra|ram] => audio/x-realaudio
  25.   [wav] => audio/wav
  26.   [ogg|oga] => audio/ogg
  27.   [mid|midi] => audio/midi
  28.   [wma] => audio/wma
  29.   [mka] => audio/x-matroska
  30.   [rtf] => application/rtf
  31.   [js] => application/javascript
  32.   [pdf] => application/pdf
  33.   [swf] => application/x-shockwave-flash
  34.   [class] => application/java
  35.   [tar] => application/x-tar
  36.   [zip] => application/zip
  37.   [gz|gzip] => application/x-gzip
  38.   [rar] => application/rar
  39.   [7z] => application/x-7z-compressed
  40.   [exe] => application/x-msdownload
  41.   [doc] => application/msword
  42.   [pot|pps|ppt] => application/vnd.ms-powerpoint
  43.   [wri] => application/vnd.ms-write
  44.   [xla|xls|xlt|xlw] => application/vnd.ms-excel
  45.   [mdb] => application/vnd.ms-access
  46.   [mpp] => application/vnd.ms-project
  47.   [docx] => application/vnd.openxmlformats-officedocument.wordprocessingml.document
  48.   [docm] => application/vnd.ms-word.document.macroEnabled.12
  49.   [dotx] => application/vnd.openxmlformats-officedocument.wordprocessingml.template
  50.   [dotm] => application/vnd.ms-word.template.macroEnabled.12
  51.   [xlsx] => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  52.   [xlsm] => application/vnd.ms-excel.sheet.macroEnabled.12
  53.   [xlsb] => application/vnd.ms-excel.sheet.binary.macroEnabled.12
  54.   [xltx] => application/vnd.openxmlformats-officedocument.spreadsheetml.template
  55.   [xltm] => application/vnd.ms-excel.template.macroEnabled.12
  56.   [xlam] => application/vnd.ms-excel.addin.macroEnabled.12
  57.   [pptx] => application/vnd.openxmlformats-officedocument.presentationml.presentation
  58.   [pptm] => application/vnd.ms-powerpoint.presentation.macroEnabled.12
  59.   [ppsx] => application/vnd.openxmlformats-officedocument.presentationml.slideshow
  60.   [ppsm] => application/vnd.ms-powerpoint.slideshow.macroEnabled.12
  61.   [potx] => application/vnd.openxmlformats-officedocument.presentationml.template
  62.   [potm] => application/vnd.ms-powerpoint.template.macroEnabled.12
  63.   [ppam] => application/vnd.ms-powerpoint.addin.macroEnabled.12
  64.   [sldx] => application/vnd.openxmlformats-officedocument.presentationml.slide
  65.   [sldm] => application/vnd.ms-powerpoint.slide.macroEnabled.12
  66.   [onetoc|onetoc2|onetmp|onepkg] => application/onenote
  67.   [odt] => application/vnd.oasis.opendocument.text
  68.   [odp] => application/vnd.oasis.opendocument.presentation
  69.   [ods] => application/vnd.oasis.opendocument.spreadsheet
  70.   [odg] => application/vnd.oasis.opendocument.graphics
  71.   [odc] => application/vnd.oasis.opendocument.chart
  72.   [odb] => application/vnd.oasis.opendocument.database
  73.   [odf] => application/vnd.oasis.opendocument.formula
  74.   [wp|wpd] => application/wordperfect

 

如果想修改文件上传大小,方法如下:

在根目录新建一个php.ini文件,添加以下代码

upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300

 

如果是apache服务器可以在.htaccess文件添加以下代码:

php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300

 

如果想更大,只需将64M改为你想要的大小。

 

云中客总结:以上方面提供了限制某些后缀的上传,也简单介绍了下限制上传容量的修改方法。

 

修改wordpress文件格式和大小限制

修改wordpress文件格式和大小限制

原创文章,转载时必须以链接形式注明本文来自云中客,本文固定链接:http://vr.ccyzk.com/362.htm

相关文章