From 375b47bf8300542dd7586ce0bea40c2698032b81 Mon Sep 17 00:00:00 2001 From: zhujinyong Date: Wed, 28 Apr 2021 13:12:56 +0800 Subject: [PATCH] * wrap get file size. --- module/file/control.php | 2 +- module/file/model.php | 31 +++++++++++++++++++++++++--- module/file/view/printfiles.html.php | 2 +- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/module/file/control.php b/module/file/control.php index e9c08f9a49..ff5e46caa4 100644 --- a/module/file/control.php +++ b/module/file/control.php @@ -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); diff --git a/module/file/model.php b/module/file/model.php index c798587d83..1a2252c579 100644 --- a/module/file/model.php +++ b/module/file/model.php @@ -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'); + } + } } diff --git a/module/file/view/printfiles.html.php b/module/file/view/printfiles.html.php index b7de5a98cf..e4c7c2a783 100644 --- a/module/file/view/printfiles.html.php +++ b/module/file/view/printfiles.html.php @@ -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; }