diff --git a/application/common/library/Upload.php b/application/common/library/Upload.php index 66afc1dc8d3d12ad5fe249df56eea86dd6913fb1..962e75ba923f3d62e38026fe8e006ce04df6ac25 100644 --- a/application/common/library/Upload.php +++ b/application/common/library/Upload.php @@ -36,6 +36,13 @@ class Upload protected $error = ''; + /** + * 保存文件的跟地址 + * + * @var string + */ + protected $saveRootPath = ROOT_PATH . 'public'; + /** * @var \think\File */ @@ -325,7 +332,7 @@ class Upload $uploadDir = substr($savekey, 0, strripos($savekey, '/') + 1); $fileName = substr($savekey, strripos($savekey, '/') + 1); - $destDir = ROOT_PATH . 'public' . str_replace('/', DS, $uploadDir); + $destDir = $this->saveRootPath . str_replace('/', DS, $uploadDir); $sha1 = $this->file->hash(); @@ -380,6 +387,17 @@ class Upload return $attachment; } + /** + * 设置保存文件的根地址 + * + * @param string $path + * @return self + */ + public function setSaveRootPath($path) { + $this->saveRootPath = $path; + return $this; + } + public function setError($msg) { $this->error = $msg;