Forgot password?
 Create new account
View 77|Reply 1

Discuz! 增加允许上传的图片格式

[Copy link]

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

hbghlyj Posted at 2024-11-2 20:42:41 |Read mode
Discuz! 增加允许上传的图片格式

打开 source/class/discuz/discuz_upload.php 文件,查找:
  1. static $imgext  = array('jpg', 'jpeg', 'gif', 'png', 'bmp');
Copy the Code

修改为:
  1. static $imgext  = array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'svg');
Copy the Code


接着将第 107到130 行的
  1.         function get_image_info($target, $allowswf = false) {
  2.                 $ext = discuz_upload::fileext($target);
  3.                 $isimage = discuz_upload::is_image_ext($ext);
  4.                 if(!$isimage && ($ext != 'swf' || !$allowswf)) {
  5.                         return false;
  6.                 } elseif(!is_readable($target)) {
  7.                         return false;
  8.                 } elseif($imageinfo = @getimagesize($target)) {
  9.                         list($width, $height, $type) = !empty($imageinfo) ? $imageinfo : array('', '', '');
  10.                         $size = $width * $height;
  11.                         if((!getglobal('setting/imagelib') && $size > (getglobal('setting/gdlimit') ? getglobal('setting/gdlimit') : 16777216)) || $size < 16 ) {
  12.                                 return false;
  13.                         } elseif($ext == 'swf' && $type != 4 && $type != 13) {
  14.                                 return false;
  15.                         } elseif($isimage && !in_array($type, array(1,2,3,6,13))) {
  16.                                 return false;
  17.                         } elseif(!$allowswf && ($ext == 'swf' || $type == 4 || $type == 13)) {
  18.                                 return false;
  19.                         }
  20.                         return $imageinfo;
  21.                 } else {
  22.                         return false;
  23.                 }
  24.         }
Copy the Code

修改为:
  1.         function get_image_info($target, $allowswf = false) {
  2.                 $ext = discuz_upload::fileext($target);
  3.                 $isimage = discuz_upload::is_image_ext($ext);
  4.                 if(!$isimage && ($ext != 'swf' || !$allowswf)) {
  5.                         return false;
  6.                 } elseif(!is_readable($target)) {
  7.                         return false;
  8.                 } elseif($imageinfo = @getimagesize($target)) {
  9.                         list($width, $height, $type) = !empty($imageinfo) ? $imageinfo : array('', '', '');
  10.                         $size = $width * $height;
  11.                         if((!getglobal('setting/imagelib') && $size > (getglobal('setting/gdlimit') ? getglobal('setting/gdlimit') : 16777216)) || $size < 16 ) {
  12.                                 return false;
  13.                         }
  14.                         return $imageinfo;
  15.                 } else {
  16.                         return false;
  17.                 }
  18.         }
Copy the Code


然后再打开 source/function/function_upload.php 文件,将第 22 行修改为:
  1. $imageexts = array('jpg','jpeg','gif','png','bmp','webp');
Copy the Code

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

 Author| hbghlyj Posted at 2024-11-2 20:44:24
我们可以测试一下吗?选择用户较少的时间

手机版Mobile version|Leisure Math Forum

2025-4-20 11:53 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list