file('image'); return self::compressAndSave(Filesystem::putFile( $path, $file)); } /** * 多图片上传 * @param array $files * @param $path * @return array */ public static function uploadImageAll(array $files,$path = 'topic') { //$files = request()->file('image'); $saveName = []; foreach($files as $file){ $saveName[] = Filesystem::putFile( $path, $file); } return $saveName; } /** * 图片压缩 * @param $path * @return mixed */ public static function compressAndSave($path) { // 获取根目录 $rootPath = app()->getRootPath(); $storage = config('filesystem.disks.public.url'); // 获取绝对路径 $absolutePath = $rootPath . 'public/' . "{$storage}/" . $path; $extension = pathinfo($absolutePath, PATHINFO_EXTENSION); $image = Image::make($absolutePath); $image->encode($extension,10)->save($absolutePath); return $path; } }