xiaoz 6 years ago
parent
commit
ed5e50e20e
  1. 10
      application/config/mimes.php
  2. 8
      application/controllers/Upload.php
  3. 2
      application/helpers/basic_helper.php
  4. 4
      application/libraries/Image.php
  5. 2
      data/version.txt
  6. 4
      static/embed.js

10
application/config/mimes.php

@ -72,10 +72,10 @@ return array(
'ra' => 'audio/x-realaudio', 'ra' => 'audio/x-realaudio',
'rv' => 'video/vnd.rn-realvideo', 'rv' => 'video/vnd.rn-realvideo',
'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'), 'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'),
'bmp' => array('image/bmp', 'image/x-bmp', 'image/x-bitmap', 'image/x-xbitmap', 'image/x-win-bitmap', 'image/x-windows-bmp', 'image/ms-bmp', 'image/x-ms-bmp', 'application/bmp', 'application/x-bmp', 'application/x-win-bitmap'), 'bmp' => array('image/bmp', 'image/x-bmp', 'image/x-bitmap', 'image/x-xbitmap', 'image/x-win-bitmap', 'image/x-windows-bmp', 'image/ms-bmp', 'image/x-ms-bmp', 'application/bmp', 'application/x-bmp', 'application/x-win-bitmap','image/jpeg', 'image/pjpeg', 'image/png', 'image/gif'),
'gif' => 'image/gif', 'gif' => array('image/jpeg', 'image/pjpeg', 'image/png', 'image/gif', 'image/bmp', 'image/x-ms-bmp'),
'jpeg' => array('image/jpeg', 'image/pjpeg'), 'jpeg' => array('image/jpeg', 'image/pjpeg', 'image/png', 'image/gif', 'image/bmp', 'image/x-ms-bmp'),
'jpg' => array('image/jpeg', 'image/pjpeg'), 'jpg' => array('image/jpeg', 'image/pjpeg', 'image/png', 'image/gif', 'image/bmp', 'image/x-ms-bmp'),
'jpe' => array('image/jpeg', 'image/pjpeg'), 'jpe' => array('image/jpeg', 'image/pjpeg'),
'jp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), 'jp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'j2k' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), 'j2k' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
@ -85,7 +85,7 @@ return array(
'jpm' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), 'jpm' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'mj2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), 'mj2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'mjp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'), 'mjp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'png' => array('image/png', 'image/x-png'), 'png' => array('image/png', 'image/x-png', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/bmp', 'image/x-ms-bmp'),
'tiff' => 'image/tiff', 'tiff' => 'image/tiff',
'tif' => 'image/tiff', 'tif' => 'image/tiff',
'css' => array('text/css', 'text/plain'), 'css' => array('text/css', 'text/plain'),

8
application/controllers/Upload.php

@ -65,6 +65,7 @@
// var_dump(); // var_dump();
$config['upload_path'] = $upload_path; $config['upload_path'] = $upload_path;
$config['allowed_types'] = 'gif|jpg|jpeg|png|bmp|webp'; $config['allowed_types'] = 'gif|jpg|jpeg|png|bmp|webp';
//$config['allowed_types'] = 'image/jpeg|image/png|image/gif|image/bmp|image/x-ms-bmp|image/webp';
$config['max_size'] = 5120; $config['max_size'] = 5120;
$config['file_ext_tolower'] = TRUE; //文件名转换为小写 $config['file_ext_tolower'] = TRUE; //文件名转换为小写
$config['overwrite'] = TRUE; //覆盖同名文件 $config['overwrite'] = TRUE; //覆盖同名文件
@ -123,11 +124,16 @@
} }
//CI获取获取.bmp 图片的像素,认为.bmp不是图像类型,改用其它方法获取像素 //CI获取获取.bmp 图片的像素,认为.bmp不是图像类型,改用其它方法获取像素
if(($data['file_type'] == 'image/x-ms-bmp') OR ($data['file_type'] == 'image/webp')){ if( $data['file_type'] === 'image/x-ms-bmp' ){
$tmpinfo = getimagesize($full_path); $tmpinfo = getimagesize($full_path);
$data['image_width'] = $tmpinfo[0]; $data['image_width'] = $tmpinfo[0];
$data['image_height'] = $tmpinfo[1]; $data['image_height'] = $tmpinfo[1];
} }
//webp的图片暂时无法获取宽高,则设置为0
if($data['file_type'] === 'image/webp'){
$data['image_width'] = 0;
$data['image_height'] = 0;
}
//查询图片是否上传过 //查询图片是否上传过
if($imginfo = $this->query->repeat($imgid)){ if($imginfo = $this->query->repeat($imgid)){

2
application/helpers/basic_helper.php

@ -62,7 +62,9 @@
case 'image/png': case 'image/png':
case 'image/jpeg': case 'image/jpeg':
case 'image/bmp': case 'image/bmp':
case 'image/x-ms-bmp':
case 'image/webp': case 'image/webp':
case 'image/svg+xml':
return TRUE; return TRUE;
break; break;
default: default:

4
application/libraries/Image.php

@ -35,8 +35,8 @@
// 创建缩略图 // 创建缩略图
//原图宽高大于缩略图 //原图宽高大于缩略图
if(($img_w > $width) || ($img_h > $height)){ if(($img_w > $width) || ($img_h > $height)){
//如果是WEBP则不裁剪 //如果是WEBP/SVG则不裁剪
if($mime === 'image/webp'){ if(($mime === 'image/webp') OR ($mime === 'image/svg+xml')){
return FALSE; return FALSE;
} }
//检测是否支持ImageMagick //检测是否支持ImageMagick

2
data/version.txt

@ -1 +1 @@
v2.22-20190427 v2.23-20190429

4
static/embed.js

@ -43,6 +43,7 @@ layui.use(['upload','form','element','layer','flow'], function(){
} }
,accept:'file' ,accept:'file'
,acceptMime:'image/webp,image/jpeg,image/pjpeg,image/bmp,image/png,image/x-png,image/gif' ,acceptMime:'image/webp,image/jpeg,image/pjpeg,image/bmp,image/png,image/x-png,image/gif'
,exts: 'jpg|jpeg|png|gif|bmp|webp'
,size:5120 ,size:5120
,before: function(obj){ //obj参数包含的信息,跟 choose回调完全一致,可参见上文。 ,before: function(obj){ //obj参数包含的信息,跟 choose回调完全一致,可参见上文。
layer.load(); //上传loading layer.load(); //上传loading
@ -82,6 +83,9 @@ layui.use(['upload','form','element','layer','flow'], function(){
upload.render({ upload.render({
elem: '#multiple' elem: '#multiple'
,url: '/upload/localhost' ,url: '/upload/localhost'
,accept:'file'
,acceptMime:'image/webp,image/jpeg,image/pjpeg,image/bmp,image/png,image/x-png,image/gif'
,exts: 'jpg|jpeg|png|gif|bmp|webp'
,multiple:true ,multiple:true
,size:5120 ,size:5120
,number:5 //可同时上传数量 ,number:5 //可同时上传数量

Loading…
Cancel
Save