| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 | 
							- <?php
 
- namespace app\common\api;
 
- /**
 
-  * Description of UploadApi
 
-  *
 
-  * @author sgq
 
-  */
 
- class UploadApi {
 
-     protected $fileSize = 5 * 1024 * 1024;
 
-     protected $fileExt = "jpg,png,gif,pdf";
 
-     protected $fileMime = "image/jpg,image/png,image/gif,application/pdf";
 
-     public function __construct($config = []) {
 
-         $this->fileSize = $config["maxSize"] ?: $this->fileSize;
 
-         $this->fileExt = $config["fileExt"] ?: $this->fileExt;
 
-         $this->fileMime = $config["fileMime"] ?: $this->fileMime;
 
-     }
 
-     /**
 
-      * 批量上传文件
 
-      * @param type $files
 
-      * @return type
 
-      */
 
-     public function uploadList($files) {
 
-         try {
 
-             validate(['image' => 'fileSize:' . $this->maxSize . '|fileExt:' . $this->fileExt . '|fileMime:' . $this->fileMime])
 
-                     ->check($files);
 
-             $savename = [];
 
-             foreach ($files as $file) {
 
-                 $savename[] = \think\facade\Filesystem::disk("public")->putFile('topic', $file);
 
-             }
 
-             return $savename;
 
-         } catch (\think\exception\ValidateException $e) {
 
-             echo $e->getMessage();
 
-         }
 
-     }
 
-     /**
 
-      * 单个文件上传
 
-      * @param type $file
 
-      * @return type
 
-      */
 
-     public function uploadOne($file) {
 
-         try {
 
-             validate(['image' => 'fileSize:' . $this->maxSize . '|fileExt:' . $this->fileExt . '|fileMime:' . $this->fileMime])
 
-                     ->check($file);
 
-             $savename = \think\facade\Filesystem::disk("public")->putFile('topic', $file);
 
-             return $savename;
 
-         } catch (\think\exception\ValidateException $e) {
 
-             echo $e->getMessage();
 
-         }
 
-     }
 
- }
 
 
  |