wesmiler 1 month ago
parent
commit
722698af00
2 changed files with 13 additions and 7 deletions
  1. 12 6
      app/Helpers/common.php
  2. 1 1
      app/Services/QiniuService.php

+ 12 - 6
app/Helpers/common.php

@@ -1884,13 +1884,7 @@ if (!function_exists('upload_image')) {
             return message("文件格式不正确:" . $ext, false);
         }
 
-        // 文件路径
-        $file_dir = ($file_path ? ATTACHMENT_PATH . '/images/' . $file_path : UPLOAD_TEMP_PATH) . "/" . date('Ymd');
 
-        // 检测文件路径是否存在,不存在则创建
-        if (!file_exists($file_dir)) {
-            mkdir($file_dir, 0777, true);
-        }
 
         // 文件名称
         $file_name = ($userId? $userId.'_'.str_replace('=','',base64_encode(date('YmdHis').$userId.$original_name)): str_replace('=','',base64_encode(date('YmdHis').$original_name)));
@@ -1898,12 +1892,24 @@ if (!function_exists('upload_image')) {
 
         $driver = \App\Services\ConfigService::make()->getConfigByCode('file_upload_driver','local');
         if($driver == 'qiniu'){
+            // 文件路径
+            $file_dir = ($file_path ? ATTACHMENT_PATH . '/images/' . $file_path : ATTACHMENT_PATH.'/images') . "/" . date('Ymd');
+
+
             // 上传云
             $file_path = str_replace(ATTACHMENT_PATH, '', $file_dir) . '/' . $file_name;
             if(!$file_path = \App\Services\QiniuService::make()->upload($file_path, $file)){
                 return message(\App\Services\QiniuService::make()->getError(), false);
             }
         }else{
+            // 文件路径
+            $file_dir = ($file_path ? ATTACHMENT_PATH . '/images/' . $file_path : UPLOAD_TEMP_PATH) . "/" . date('Ymd');
+
+            // 检测文件路径是否存在,不存在则创建
+            if (!file_exists($file_dir)) {
+                mkdir($file_dir, 0777, true);
+            }
+
             // 重命名保存
             $path = $file->move($file_dir, $file_name);
             // 文件临时路径

+ 1 - 1
app/Services/QiniuService.php

@@ -79,7 +79,7 @@ class QiniuService extends BaseService
             $this->error = 'QINIU图片上传失败:' . $err->getMessage();
             return false;
         } else {
-            return $this->host . '/' . $filename;
+            return $this->host . '/' . trim($filename,'/');
         }
     }
 }