Skip to content

Commit

Permalink
优化阿里云oss上传
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxi2015 committed Jun 1, 2021
1 parent c496004 commit 9c0ceeb
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app/Utils/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ public function __construct($name='file', $uploadPath='upload', $width=100, $hei

/**
* @param RequestInterface $request
* @return array|bool
* @param string $dirName
* @return array
* @throws \League\Flysystem\FileExistsException
*/
public function uploadFile(RequestInterface $request)
public function uploadFile(RequestInterface $request, $dirName='')
{
if (!$request->hasFile($this->name)) {
throw new BusinessException(ErrorCode::BAD_REQUEST, '上传文件名称不存在');
Expand All @@ -109,9 +111,14 @@ public function uploadFile(RequestInterface $request)
if (!in_array($this->extension, $this->limitType)) {
throw new BusinessException(ErrorCode::UNAUTHORIZED, '文件上传格式不支持,支持格式:' . implode(', ', $this->limitType));
}
$objectName = env('RESOURCE_TEMP_PATH');
$objectName = env('RESOURCE_TEMP_PATH') ?: BASE_PATH . DIRECTORY_SEPARATOR;

$filePath = $this->uploadPath . DIRECTORY_SEPARATOR;
if ($dirName) {
$filePath = $filePath . $dirName. DIRECTORY_SEPARATOR;
}
$filePath = $filePath . date('Y-m-d') . DIRECTORY_SEPARATOR;

$filePath = $this->uploadPath . DIRECTORY_SEPARATOR . 'mp'. DIRECTORY_SEPARATOR . date('Y-m-d') . DIRECTORY_SEPARATOR;
$res = Common::mkDir($objectName . $filePath);
if (!$res) {
throw new BusinessException(ErrorCode::UNAUTHORIZED, '资源文件夹创建失败,请检查目录权限');
Expand Down

0 comments on commit 9c0ceeb

Please sign in to comment.