* wrap get file size.

This commit is contained in:
zhujinyong
2021-04-28 13:12:56 +08:00
parent 2e03100a96
commit 375b47bf83
3 changed files with 30 additions and 5 deletions
+1 -1
View File
@@ -63,7 +63,7 @@ class file extends control
die(json_encode(array('error' => 1, 'message' => $this->lang->file->errorFileUpload)));
}
}
if(@helper::saveFile($file['tmpname'], $this->file->savePath . $this->file->getSaveName($file['pathname'])))
if(@move_uploaded_file($file['tmpname'], $this->file->savePath . $this->file->getSaveName($file['pathname'])))
{
/* Compress image for jpg and bmp. */
$file = $this->file->compressImage($file);
+28 -3
View File
@@ -262,7 +262,7 @@ class fileModel extends model
}
else
{
if(!helper::saveFile($file['tmpname'], $tmpFileChunkPath)) return false;
if(!move_uploaded_file($file['tmpname'], $tmpFileChunkPath)) return false;
}
if($file['chunk'] == ($file['chunks'] - 1))
@@ -278,7 +278,7 @@ class fileModel extends model
}
else
{
if(!helper::saveFile($file['tmpname'], $file['realpath'])) return false;
if(!move_uploaded_file($file['tmpname'], $file['realpath'])) return false;
$uploadFile['extension'] = $file['extension'];
$uploadFile['pathname'] = $file['pathname'];
@@ -471,7 +471,7 @@ class fileModel extends model
$pathName = $filePath->pathname;
$realPathName = $this->savePath . $this->getRealPathName($pathName);
if(!is_dir(dirname($realPathName))) mkdir(dirname($realPathName));
helper::saveFile($file['tmpname'], $realPathName);
move_uploaded_file($file['tmpname'], $realPathName);
$file['pathname'] = $pathName;
$file = $this->compressImage($file);
@@ -966,4 +966,29 @@ class fileModel extends model
die();
}
}
/**
* Get image size.
*
* @access public
* @param object $file
* @return array
*/
public function getImageSize($file)
{
if($this->config->file->storageType == 'fs')
{
return getimagesize($file->realPath);
}
else if($this->config->file->storageType == 's3')
{
$this->app->loadClass('ossclient', true);
$config = $this->config->file;
$ossClient = new ossclient($config->accessKeyId, $config->accessKeySecret, $config->endpoint, $config->bucket);
$info = $ossClient->getImageInfo($file->pathname);
return array($info->ImageWidth->value, $info->ImageHeight->value, 'img');
}
}
}
+1 -1
View File
@@ -53,7 +53,7 @@ $sessionString .= session_name() . '=' . session_id();
$imageWidth = 0;
if(stripos('jpg|jpeg|gif|png|bmp', $file->extension) !== false)
{
$imageSize = getimagesize($file->realPath);
$imageSize = $this->file->getImageSize($file);
$imageWidth = $imageSize ? $imageSize[0] : 0;
}