Merge branch 'master' of github.com:easysoft/zentaopms
This commit is contained in:
@@ -5,4 +5,4 @@ $config->file->mimes['csv'] = 'text/csv';
|
||||
$config->file->mimes['default'] = 'application/octet-stream';
|
||||
|
||||
$config->file->imageExtensions = array('jpeg', 'jpg', 'gif', 'png');
|
||||
$config->file->imageFmt = array('.jpg', '.bmp', '.jpeg');
|
||||
$config->file->image2Compress = array('.jpg', '.bmp', '.jpeg');
|
||||
|
||||
@@ -52,13 +52,7 @@ class file extends control
|
||||
if(@move_uploaded_file($file['tmpname'], $this->file->savePath . $file['pathname']))
|
||||
{
|
||||
/* Compress image for jpg and bmp. */
|
||||
$compressedImage = $this->file->compressImage($file['pathname']);
|
||||
if($compressedImage)
|
||||
{
|
||||
$file['pathname'] = $compressedImage['pathname'];
|
||||
$file['extension'] = $compressedImage['extension'];
|
||||
$file['size'] = $compressedImage['size'];
|
||||
}
|
||||
$file = $this->file->compressImage($file);
|
||||
|
||||
$file['addedBy'] = $this->app->user->account;
|
||||
$file['addedDate'] = helper::today();
|
||||
|
||||
+25
-27
@@ -78,13 +78,7 @@ class fileModel extends model
|
||||
{
|
||||
if($file['size'] == 0) continue;
|
||||
move_uploaded_file($file['tmpname'], $this->savePath . $file['pathname']);
|
||||
$compressedImage = $this->compressImage($file['pathname']);
|
||||
if($compressedImage)
|
||||
{
|
||||
$file['pathname'] = $compressedImage['pathname'];
|
||||
$file['extension'] = $compressedImage['extension'];
|
||||
$file['size'] = $compressedImage['size'];
|
||||
}
|
||||
$file = $this->compressImage($file);
|
||||
|
||||
$file['objectType'] = $objectType;
|
||||
$file['objectID'] = $objectID;
|
||||
@@ -246,9 +240,11 @@ class fileModel extends model
|
||||
$realPathName= $this->savePath . $pathName;
|
||||
if(!is_dir(dirname($realPathName)))mkdir(dirname($realPathName));
|
||||
move_uploaded_file($file['tmpname'], $realPathName);
|
||||
$compressImage = $this->compressImage($pathName);
|
||||
if($compressImage) $file['size'] = $compressedImage['size'];
|
||||
|
||||
$file['pathname'] = $pathName;
|
||||
$file = $this->compressImage($file);
|
||||
|
||||
$fileInfo = new stdclass();
|
||||
$fileInfo->addedBy = $this->app->user->account;
|
||||
$fileInfo->addedDate = helper::now();
|
||||
$fileInfo->size = $file['size'];
|
||||
@@ -440,8 +436,16 @@ class fileModel extends model
|
||||
foreach($files as $i => $uploadFile)
|
||||
{
|
||||
if($uploadFile['folder']) continue;
|
||||
$fileName = mb_convert_encoding($uploadFile['filename'], 'UTF-8', 'gbk');
|
||||
$fileName = substr($fileName, strrpos($fileName, '/') + 1);
|
||||
$fileName = $uploadFile['filename'];
|
||||
if(function_exists('iconv'))
|
||||
{
|
||||
$fileName = iconv('gbk', 'utf-8//TRANSLIT', $fileName);
|
||||
}
|
||||
elseif(function_exists('mb_convert_encoding'))
|
||||
{
|
||||
$fileName = mb_convert_encoding($fileName, 'utf-8', 'gbk');
|
||||
}
|
||||
if(($pos = strrpos($fileName, '/')) !== false) $fileName = substr($fileName, $pos + 1);
|
||||
|
||||
$file = array();
|
||||
$file['extension'] = $this->getExtension($fileName);
|
||||
@@ -483,39 +487,33 @@ class fileModel extends model
|
||||
/**
|
||||
* Compress image
|
||||
*
|
||||
* @param string $pathName
|
||||
* @param array $file
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function compressImage($pathName)
|
||||
public function compressImage($file)
|
||||
{
|
||||
if(!extension_loaded('gd')) return false;
|
||||
if(!extension_loaded('gd')) return $file;
|
||||
|
||||
$pathName = $file['pathname'];
|
||||
$fileName = $this->savePath . $pathName;
|
||||
$suffix = strrchr($fileName, '.');
|
||||
$lowerSuffix = strtolower($suffix);
|
||||
|
||||
if(!in_array($lowerSuffix, $this->config->file->imageFmt)) return false;
|
||||
if(!in_array($lowerSuffix, $this->config->file->image2Compress)) return $file;
|
||||
|
||||
$quality = 85;
|
||||
$newSuffix = '.jpg';
|
||||
$compressedName = str_replace($suffix, $newSuffix, $pathName);
|
||||
|
||||
$res = '';
|
||||
if($lowerSuffix == '.bmp')
|
||||
{
|
||||
$res = $this->imagecreatefrombmp($fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
$res = imagecreatefromjpeg($fileName);
|
||||
}
|
||||
|
||||
$res = $lowerSuffix == '.bmp' ? $this->imagecreatefrombmp($fileName) : imagecreatefromjpeg($fileName);
|
||||
imagejpeg($res, $this->savePath . $compressedName, $quality);
|
||||
if($fileName != $this->savePath . $compressedName) unlink($fileName);
|
||||
|
||||
|
||||
return array('pathname' => $compressedName, 'extension' => ltrim($newSuffix, '.'), 'size' => filesize($this->savePath . $compressedName));
|
||||
$file['pathname'] = $compressedName;
|
||||
$file['extension'] = ltrim($newSuffix, '.');
|
||||
$file['size'] = filesize($this->savePath . $compressedName);
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user