diff --git a/framework/helper.class.php b/framework/helper.class.php index 6f964ec9eb..ce87666f16 100644 --- a/framework/helper.class.php +++ b/framework/helper.class.php @@ -66,7 +66,7 @@ class helper extends baseHelper * @access public * @return string */ - static public function jsonEncode4Parse($data, $options = 0) + public static function jsonEncode4Parse($data, $options = 0) { $json = json_encode($data); if($options) $json = str_replace(array("'", '"'), array('\u0027', '\u0022'), $json); @@ -86,7 +86,7 @@ class helper extends baseHelper * @access public * @return string */ - static public function convertEncoding($string, $fromEncoding, $toEncoding = 'utf-8') + public static function convertEncoding($string, $fromEncoding, $toEncoding = 'utf-8') { $toEncoding = str_replace('utf8', 'utf-8', $toEncoding); if(function_exists('mb_convert_encoding')) @@ -121,7 +121,7 @@ class helper extends baseHelper * * @return bool|float */ - static public function workDays($begin, $end) + public static function workDays($begin, $end) { $begin = strtotime($begin); $end = strtotime($end); @@ -228,6 +228,30 @@ class helper extends baseHelper $version ); } + + /** + * Save file to storage: fs(www/data/upload) or s3(s3, oss, minio) + * + * @param string $tmpFile + * @param string $fileName + * @access public + * @return bool + */ + public static function saveFile($tmpFile, $filePath) + { + global $config; + + if(!isset($config->storageType) or $config->storageType == 'fs') + { + return move_uploaded_file($tmpFile, $filePath); + } + else if(isset($config->storageType) and $config->storageType == 's3') + { + return move_uploaded_file($tmpFile, $filePath); // TODO + } + + return false; + } } /** diff --git a/module/caselib/control.php b/module/caselib/control.php index f2e28ecbd8..6c28247299 100644 --- a/module/caselib/control.php +++ b/module/caselib/control.php @@ -505,7 +505,7 @@ class caselib extends control $file = $file[0]; $fileName = $this->file->savePath . $this->file->getSaveName($file['pathname']); - move_uploaded_file($file['tmpname'], $fileName); + helper::saveFile($file['tmpname'], $fileName); $rows = $this->file->parseCSV($fileName); $fields = $this->testcase->getImportFields($productID); diff --git a/module/extension/control.php b/module/extension/control.php index f88933e476..ceac268e7e 100644 --- a/module/extension/control.php +++ b/module/extension/control.php @@ -431,7 +431,7 @@ class extension extends control $tmpName = $_FILES['file']['tmp_name']; $fileName = $_FILES['file']['name']; $dest = $this->app->getTmpRoot() . "/extension/$fileName"; - move_uploaded_file($tmpName, $dest); + helper::saveFile($tmpName, $dest); $extension = basename($fileName, '.zip'); $return = $this->extension->extractPackage($extension); diff --git a/module/file/control.php b/module/file/control.php index ff5e46caa4..e9c08f9a49 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(@move_uploaded_file($file['tmpname'], $this->file->savePath . $this->file->getSaveName($file['pathname']))) + if(@helper::saveFile($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 b249e3d67c..debd0dd26a 100644 --- a/module/file/model.php +++ b/module/file/model.php @@ -97,7 +97,7 @@ class fileModel extends model foreach($files as $id => $file) { if($file['size'] == 0) continue; - if(!move_uploaded_file($file['tmpname'], $this->savePath . $this->getSaveName($file['pathname']))) return false; + if(!helper::saveFile($file['tmpname'], $this->savePath . $this->getSaveName($file['pathname']))) return false; $file = $this->compressImage($file); @@ -262,7 +262,7 @@ class fileModel extends model } else { - if(!move_uploaded_file($file['tmpname'], $tmpFileChunkPath)) return false; + if(!helper::saveFile($file['tmpname'], $tmpFileChunkPath)) return false; } if($file['chunk'] == ($file['chunks'] - 1)) @@ -278,7 +278,7 @@ class fileModel extends model } else { - if(!move_uploaded_file($file['tmpname'], $file['realpath'])) return false; + if(!helper::saveFile($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)); - move_uploaded_file($file['tmpname'], $realPathName); + helper::saveFile($file['tmpname'], $realPathName); $file['pathname'] = $pathName; $file = $this->compressImage($file); diff --git a/module/testcase/control.php b/module/testcase/control.php index 17a3a329de..675e0aafd1 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -1522,7 +1522,7 @@ class testcase extends control $file = $file[0]; $fileName = $this->file->savePath . $this->file->getSaveName($file['pathname']); - move_uploaded_file($file['tmpname'], $fileName); + helper::saveFile($file['tmpname'], $fileName); $rows = $this->file->parseCSV($fileName); $fields = $this->testcase->getImportFields($productID); diff --git a/module/testtask/model.php b/module/testtask/model.php index 93acd2e789..4ae0209b89 100644 --- a/module/testtask/model.php +++ b/module/testtask/model.php @@ -1628,7 +1628,7 @@ class testtaskModel extends model $file = $file[0]; $fileName = $this->file->savePath . $this->file->getSaveName($file['pathname']); - move_uploaded_file($file['tmpname'], $fileName); + helper::saveFile($file['tmpname'], $fileName); if(simplexml_load_file($fileName) === false) { dao::$errors[] = $this->lang->testtask->cannotBeParsed;