Commit 5f798f59 authored by chentianyu's avatar chentianyu

oss 路径加appName

parent 62a51b86
...@@ -33,6 +33,11 @@ class UploadOssService ...@@ -33,6 +33,11 @@ class UploadOssService
*/ */
private $appDev; private $appDev;
/**
* @var string
*/
private $appName;
public static $options = [ public static $options = [
'maxSize' => 10 * 1024 * 1024, // 文件大小,10M 'maxSize' => 10 * 1024 * 1024, // 文件大小,10M
'mime' => ['jpeg', 'png', 'gif', 'jpg', 'svg', 'txt', 'pdf', 'xlsx', 'xls', 'doc', 'docx', 'rar', 'zip', 'csv'], // 允许上传的文件类型 'mime' => ['jpeg', 'png', 'gif', 'jpg', 'svg', 'txt', 'pdf', 'xlsx', 'xls', 'doc', 'docx', 'rar', 'zip', 'csv'], // 允许上传的文件类型
...@@ -45,6 +50,7 @@ class UploadOssService ...@@ -45,6 +50,7 @@ class UploadOssService
$ossConfig = $this->config->get('file.storage.oss'); $ossConfig = $this->config->get('file.storage.oss');
$this->urlPrefix = 'https://' . $ossConfig['bucket'] . '.' . $ossConfig['endpoint'] . '/'; $this->urlPrefix = 'https://' . $ossConfig['bucket'] . '.' . $ossConfig['endpoint'] . '/';
$this->appDev = $this->config->get('app_env'); $this->appDev = $this->config->get('app_env');
$this->appName = $this->config->get('app_name');
} }
/** /**
...@@ -61,7 +67,7 @@ class UploadOssService ...@@ -61,7 +67,7 @@ class UploadOssService
$clientFilename = $image->getClientFilename(); $clientFilename = $image->getClientFilename();
$fileName = $uniqueFileName ? ($this->genUniqueFileName() . '.' . $ext) : $clientFilename; $fileName = $uniqueFileName ? ($this->genUniqueFileName() . '.' . $ext) : $clientFilename;
$options = ['mime' => ['jpeg', 'png', 'gif', 'jpg', 'svg']]; $options = ['mime' => ['jpeg', 'png', 'gif', 'jpg', 'svg']];
$filePath = 'oss2/' . $this->appDev . "/$module/images/" . today() . "/$userId/" . $clientFilename; $filePath = 'oss2/' . $this->appDev . "/" . $this->appName . "/$module/images/" . today() . "/$userId/" . $clientFilename;
$this->upload($image, $filePath, $options); $this->upload($image, $filePath, $options);
$model = new FileModel(); $model = new FileModel();
$model = $model->newInstance([ $model = $model->newInstance([
...@@ -91,7 +97,7 @@ class UploadOssService ...@@ -91,7 +97,7 @@ class UploadOssService
$ext = $file->getExtension(); $ext = $file->getExtension();
$clientFilename = $file->getClientFilename(); $clientFilename = $file->getClientFilename();
$fileName = $uniqueFileName ? ($this->genUniqueFileName() . '.' . $ext) : $clientFilename; $fileName = $uniqueFileName ? ($this->genUniqueFileName() . '.' . $ext) : $clientFilename;
$filePath = 'oss2/' . $this->appDev . "/$module/files/" . today() . "/$userId/" . $clientFilename; $filePath = 'oss2/' . $this->appDev . "/" . $this->appName . "/$module/files/" . today() . "/$userId/" . $clientFilename;
$this->upload($file, $filePath, $options); $this->upload($file, $filePath, $options);
$model = new FileModel(); $model = new FileModel();
$model = $model->newInstance([ $model = $model->newInstance([
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment