diff --git a/src/admin/inc/inc_archives_functions.php b/src/admin/inc/inc_archives_functions.php index f9a05f52..ba45075a 100644 --- a/src/admin/inc/inc_archives_functions.php +++ b/src/admin/inc/inc_archives_functions.php @@ -124,15 +124,32 @@ function GetCurContent($body) $htd->OpenUrl($value); $itype = $htd->GetHead("content-type"); - $itype = substr($value, -4, 4); - if (!preg_match("#\.(jpg|gif|png)#i", $itype)) { - if ($itype == 'image/gif') { - $itype = ".gif"; - } else if ($itype == 'image/png') { - $itype = ".png"; - } else { - $itype = '.jpg'; - } + $isImage = true; + if ($itype == 'image/gif') { + $itype = ".gif"; + } else if ($itype == 'image/png') { + $itype = ".png"; + } else if($itype == 'video/mp4'){ + $itype = ".mp4"; + $isImage = false; + } else if (preg_match("#^text#i",$itype)){ + $itype = ".txt"; + $isImage = false; + } else if ($itype == 'application/zip'){ + $itype = ".zip"; + $isImage = false; + } else if ($itype == 'application/x-rar-compressed'){ + $itype = ".rar"; + $isImage = false; + } else if($itype == 'image/jpeg') { + $itype = '.jpg'; + } else if($itype == 'image/bmp') { + $itype = '.bmp'; + } else if($itype == 'image/svg+xml') { + $itype = '.svg'; + $isImage = false; + } else { + continue; } $milliSecondN = dd2char($milliSecond.mt_rand(1000, 8000)); $value = trim($value); @@ -141,7 +158,10 @@ function GetCurContent($body) $rs = $htd->SaveToBin($rndFileName); if ($rs) { $info = ''; - $imginfos = GetImageSize($rndFileName, $info); + $imginfos = array(0,0); + if ($isImage) { + $imginfos = GetImageSize($rndFileName, $info); + } $fsize = filesize($rndFileName); //保存图片附件信息 $inquery = "INSERT INTO `#@__uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid) @@ -153,7 +173,9 @@ function GetCurContent($body) $fileurl = $cfg_basehost.$fileurl; } $body = str_replace($value, $fileurl, $body); - @WaterImg($rndFileName, 'down'); + if ($isImage) { + @WaterImg($rndFileName, 'down'); + } } } $htd->Close(); diff --git a/src/system/helpers/image.helper.php b/src/system/helpers/image.helper.php index 58c7ad34..ee09395a 100755 --- a/src/system/helpers/image.helper.php +++ b/src/system/helpers/image.helper.php @@ -24,72 +24,78 @@ if (!function_exists('ImageResize')) { function ImageResize($srcFile, $toW, $toH, $toFile = "") { global $cfg_photo_type; - if ($toFile == '') $toFile = $srcFile; - $info = ''; - $srcInfo = GetImageSize($srcFile, $info); - switch ($srcInfo[2]) { - case 1: - if (!$cfg_photo_type['gif']) return FALSE; - $im = imagecreatefromgif($srcFile); - break; - case 2: - if (!$cfg_photo_type['jpeg']) return FALSE; - $im = imagecreatefromjpeg($srcFile); - break; - case 3: - if (!$cfg_photo_type['png']) return FALSE; - $im = imagecreatefrompng($srcFile); - break; - case 6: - if (!$cfg_photo_type['bmp']) return FALSE; - $im = imagecreatefromwbmp($srcFile); - break; - } - $srcW = ImageSX($im); - $srcH = ImageSY($im); - if ($srcW <= $toW && $srcH <= $toH) return TRUE; - $toWH = $toW / $toH; - $srcWH = $srcW / $srcH; - if ($toWH <= $srcWH) { - $ftoW = $toW; - $ftoH = $ftoW * ($srcH / $srcW); - } else { - $ftoH = $toH; - $ftoW = $ftoH * ($srcW / $srcH); - } - if ($srcW > $toW || $srcH > $toH) { - if (function_exists("imagecreateTRUEcolor")) { - @$ni = imagecreateTRUEcolor($ftoW, $ftoH); - if ($ni) { - imagecopyresampled($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH); - } else { - $ni = imagecreate($ftoW, $ftoH); - imagecopyresized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH); - } - } else { - $ni = imagecreate($ftoW, $ftoH); - imagecopyresized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH); - } + try { + if ($toFile == '') $toFile = $srcFile; + $info = ''; + $srcInfo = GetImageSize($srcFile, $info); switch ($srcInfo[2]) { case 1: - imagegif($ni, $toFile); + if (!$cfg_photo_type['gif']) return FALSE; + $im = imagecreatefromgif($srcFile); break; case 2: - imagejpeg($ni, $toFile, 85); + if (!$cfg_photo_type['jpeg']) return FALSE; + $im = imagecreatefromjpeg($srcFile); break; case 3: - imagepng($ni, $toFile); + if (!$cfg_photo_type['png']) return FALSE; + $im = imagecreatefrompng($srcFile); break; case 6: - imagebmp($ni, $toFile); + if (!$cfg_photo_type['bmp']) return FALSE; + $im = imagecreatefromwbmp($srcFile); break; - default: - return FALSE; } - imagedestroy($ni); + $srcW = ImageSX($im); + $srcH = ImageSY($im); + if ($srcW <= $toW && $srcH <= $toH) return TRUE; + $toWH = $toW / $toH; + $srcWH = $srcW / $srcH; + if ($toWH <= $srcWH) { + $ftoW = $toW; + $ftoH = $ftoW * ($srcH / $srcW); + } else { + $ftoH = $toH; + $ftoW = $ftoH * ($srcW / $srcH); + } + if ($srcW > $toW || $srcH > $toH) { + if (function_exists("imagecreateTRUEcolor")) { + @$ni = imagecreateTRUEcolor($ftoW, $ftoH); + if ($ni) { + imagecopyresampled($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH); + } else { + $ni = imagecreate($ftoW, $ftoH); + imagecopyresized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH); + } + } else { + $ni = imagecreate($ftoW, $ftoH); + imagecopyresized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH); + } + switch ($srcInfo[2]) { + case 1: + imagegif($ni, $toFile); + break; + case 2: + imagejpeg($ni, $toFile, 85); + break; + case 3: + imagepng($ni, $toFile); + break; + case 6: + imagebmp($ni, $toFile); + break; + default: + return FALSE; + } + imagedestroy($ni); + } + imagedestroy($im); + return true; + } catch(Throwable $th) { + return false; + } catch (Exception $e) { + return false; } - imagedestroy($im); - return TRUE; } } /**