作者 赵彬吉

update

@@ -110,7 +110,7 @@ class GoogleSpeedApi @@ -110,7 +110,7 @@ class GoogleSpeedApi
110 try { 110 try {
111 if($url){ 111 if($url){
112 $params = [ 112 $params = [
113 - 'url' => $url 113 + 'url' => base64_encode($url)
114 ]; 114 ];
115 $res = HttpUtils::get('http://pagespeed.quanqiusou.cn/api.php', $params); 115 $res = HttpUtils::get('http://pagespeed.quanqiusou.cn/api.php', $params);
116 if ($res) { 116 if ($res) {
@@ -110,11 +110,12 @@ class FileController @@ -110,11 +110,12 @@ class FileController
110 */ 110 */
111 public function single(&$files){ 111 public function single(&$files){
112 $hash = hash_file('md5', $files->getPathname()); 112 $hash = hash_file('md5', $files->getPathname());
  113 + $name = $files->getClientOriginalName();
113 //查看文件是否存在 114 //查看文件是否存在
114 $fileModel = new File(); 115 $fileModel = new File();
115 $file_hash = $fileModel->read(['hash'=>$hash]); 116 $file_hash = $fileModel->read(['hash'=>$hash]);
116 if($file_hash !== false){ 117 if($file_hash !== false){
117 - return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path'])); 118 + return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path'], $name));
118 } 119 }
119 $url = $this->config['root'].$this->path; 120 $url = $this->config['root'].$this->path;
120 $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension(); 121 $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
@@ -128,8 +129,8 @@ class FileController @@ -128,8 +129,8 @@ class FileController
128 return $this->response($files->getError(), Code::USER_ERROR); 129 return $this->response($files->getError(), Code::USER_ERROR);
129 } 130 }
130 } 131 }
131 - $this->saveMysql($fileModel,$files->getSize(),$files->getClientOriginalExtension(),$fileName,$hash,$this->upload_location,$files->getMimeType());  
132 - return $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName)); 132 + $this->saveMysql($fileModel,$files->getSize(),$files->getClientOriginalExtension(),$fileName,$hash,$this->upload_location,$files->getMimeType(),$name);
  133 + return $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
133 } 134 }
134 135
135 /** 136 /**
@@ -139,7 +140,7 @@ class FileController @@ -139,7 +140,7 @@ class FileController
139 * @method :post 140 * @method :post
140 * @time :2023/7/19 16:38 141 * @time :2023/7/19 16:38
141 */ 142 */
142 - public function saveMysql(&$fileModel,$size,$image_type,$fileName,$hash,$is_cos = 0,$mime = ''){ 143 + public function saveMysql(&$fileModel,$size,$image_type,$fileName,$hash,$is_cos = 0,$mime = '',$name=''){
143 $data = [ 144 $data = [
144 'path' => $this->path.'/'.$fileName, 145 'path' => $this->path.'/'.$fileName,
145 'created_at' => date('Y-m-d H:i:s',time()), 146 'created_at' => date('Y-m-d H:i:s',time()),
@@ -149,6 +150,7 @@ class FileController @@ -149,6 +150,7 @@ class FileController
149 'refer'=>$this->param['refer'] ?? 1, 150 'refer'=>$this->param['refer'] ?? 1,
150 'is_cos'=>$is_cos, 151 'is_cos'=>$is_cos,
151 'mime'=>$mime, 152 'mime'=>$mime,
  153 + 'name'=>$name,
152 ]; 154 ];
153 $rs = $fileModel->add($data); 155 $rs = $fileModel->add($data);
154 if ($rs === false) { 156 if ($rs === false) {
@@ -168,10 +170,11 @@ class FileController @@ -168,10 +170,11 @@ class FileController
168 $data = []; 170 $data = [];
169 foreach ($files as $file) { 171 foreach ($files as $file) {
170 $fileModel = new File(); 172 $fileModel = new File();
  173 + $name = $file->getClientOriginalName();
171 $hash = hash_file('md5', $file->getPathname()); 174 $hash = hash_file('md5', $file->getPathname());
172 $file_hash = $fileModel->read(['hash'=>$hash]); 175 $file_hash = $fileModel->read(['hash'=>$hash]);
173 if($file_hash !== false){ 176 if($file_hash !== false){
174 - $data[] = $this->responseData($file_hash['path']); 177 + $data[] = $this->responseData($file_hash['path'], $name);
175 continue; 178 continue;
176 } 179 }
177 $url = $this->config['root'].'/'.$this->path; 180 $url = $this->config['root'].'/'.$this->path;
@@ -189,8 +192,8 @@ class FileController @@ -189,8 +192,8 @@ class FileController
189 } 192 }
190 $size = $file->getSize(); 193 $size = $file->getSize();
191 $mime = $file->getMimeType(); 194 $mime = $file->getMimeType();
192 - $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime);  
193 - $data[] = $this->responseData($this->path.'/'.$fileName); 195 + $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime,$name);
  196 + $data[] = $this->responseData($this->path.'/'.$fileName, $name);
194 } 197 }
195 $this->response('资源',Code::SUCCESS,$data); 198 $this->response('资源',Code::SUCCESS,$data);
196 } 199 }
@@ -230,11 +233,11 @@ class FileController @@ -230,11 +233,11 @@ class FileController
230 $this->response('指定文件不存在!', Code::USER_ERROR); 233 $this->response('指定文件不存在!', Code::USER_ERROR);
231 } 234 }
232 $fileUrl = getFileUrl($info['path'],$info['is_cos']); 235 $fileUrl = getFileUrl($info['path'],$info['is_cos']);
233 - $fileName = basename($fileUrl); // 要保存的文件名 236 +// $fileName = basename($fileUrl); // 要保存的文件名
234 // 设置响应头 237 // 设置响应头
235 header('Content-Description: File Transfer'); 238 header('Content-Description: File Transfer');
236 header('Content-Type: application/octet-stream'); 239 header('Content-Type: application/octet-stream');
237 - header('Content-Disposition: attachment; filename="' . $fileName . '"'); 240 + header('Content-Disposition: attachment; filename="' . $info['name'] . '"');
238 // 下载文件 241 // 下载文件
239 readfile($fileUrl); 242 readfile($fileUrl);
240 } 243 }
@@ -277,7 +280,7 @@ class FileController @@ -277,7 +280,7 @@ class FileController
277 } 280 }
278 $this->map['refer'] = 1; 281 $this->map['refer'] = 1;
279 $fileModel = new File(); 282 $fileModel = new File();
280 - $lists = $fileModel->list($this->map,'id',['id','hash','type','path','created_at']); 283 + $lists = $fileModel->list($this->map,'id',['id','hash','type','path','created_at','name']);
281 foreach ($lists as $k => $v){ 284 foreach ($lists as $k => $v){
282 $v['file_link'] = getFileUrl($v['path']); 285 $v['file_link'] = getFileUrl($v['path']);
283 $lists[$k] = $v; 286 $lists[$k] = $v;
@@ -292,10 +295,11 @@ class FileController @@ -292,10 +295,11 @@ class FileController
292 * @method :post 295 * @method :post
293 * @time :2023/7/26 13:41 296 * @time :2023/7/26 13:41
294 */ 297 */
295 - public function responseData($path){ 298 + public function responseData($path, $name){
296 $data = [ 299 $data = [
297 'file'=>$path, 300 'file'=>$path,
298 'file_link'=>getFileUrl($path,$this->upload_location), 301 'file_link'=>getFileUrl($path,$this->upload_location),
  302 + 'name'=>$name,
299 ]; 303 ];
300 return $data; 304 return $data;
301 } 305 }
@@ -313,7 +317,7 @@ class FileController @@ -313,7 +317,7 @@ class FileController
313 if ($info === false) { 317 if ($info === false) {
314 $this->response('指定文件不存在!', Code::USER_ERROR); 318 $this->response('指定文件不存在!', Code::USER_ERROR);
315 } 319 }
316 - $data = ['file_download'=>url('a/download_files?path='.$info['path'])]; 320 + $data = ['file_download'=>url('a/download_files?path='.$info['path']), 'name' => $info['name']];
317 $this->response('success',Code::SUCCESS,$data); 321 $this->response('success',Code::SUCCESS,$data);
318 } 322 }
319 } 323 }
@@ -180,6 +180,7 @@ class ImageController extends Controller @@ -180,6 +180,7 @@ class ImageController extends Controller
180 */ 180 */
181 public function single(&$files){ 181 public function single(&$files){
182 $hash = hash_file('md5', $files->getPathname()); 182 $hash = hash_file('md5', $files->getPathname());
  183 + $name = $files->getClientOriginalName();
183 //查看文件是否存在 184 //查看文件是否存在
184 $imageModel = new ImageModel(); 185 $imageModel = new ImageModel();
185 //查看图片是否已上传 186 //查看图片是否已上传
@@ -189,7 +190,7 @@ class ImageController extends Controller @@ -189,7 +190,7 @@ class ImageController extends Controller
189 } 190 }
190 $image_hash = $imageModel->read($param); 191 $image_hash = $imageModel->read($param);
191 if($image_hash !== false){ 192 if($image_hash !== false){
192 - return $this->response('图片资源',Code::SUCCESS,$this->responseData($image_hash['path'])); 193 + return $this->response('图片资源',Code::SUCCESS,$this->responseData($image_hash['path'], $name));
193 } 194 }
194 //保存路径 195 //保存路径
195 $url = $this->config['root'].$this->path; 196 $url = $this->config['root'].$this->path;
@@ -202,8 +203,8 @@ class ImageController extends Controller @@ -202,8 +203,8 @@ class ImageController extends Controller
202 }else{ 203 }else{
203 $files->move($url,$fileName); 204 $files->move($url,$fileName);
204 } 205 }
205 - $this->saveMysql($imageModel,$files->getSize(),$image_type,$fileName,$hash,$this->upload_location,$files->getMimeType());  
206 - return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName)); 206 + $this->saveMysql($imageModel,$files->getSize(),$image_type,$fileName,$hash,$this->upload_location,$files->getMimeType(), $name);
  207 + return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
207 } 208 }
208 209
209 /** 210 /**
@@ -213,7 +214,7 @@ class ImageController extends Controller @@ -213,7 +214,7 @@ class ImageController extends Controller
213 * @method :post 214 * @method :post
214 * @time :2023/7/19 16:38 215 * @time :2023/7/19 16:38
215 */ 216 */
216 - public function saveMysql(&$imageModel,$size,$image_type,$fileName,$hash,$is_cos = 0,$mime = ''){ 217 + public function saveMysql(&$imageModel,$size,$image_type,$fileName,$hash,$is_cos = 0,$mime = '', $name=''){
217 $data = [ 218 $data = [
218 'path' => $this->path.'/'.$fileName, 219 'path' => $this->path.'/'.$fileName,
219 'created_at' => date('Y-m-d H:i:s',time()), 220 'created_at' => date('Y-m-d H:i:s',time()),
@@ -224,6 +225,7 @@ class ImageController extends Controller @@ -224,6 +225,7 @@ class ImageController extends Controller
224 'is_cos'=>$is_cos, 225 'is_cos'=>$is_cos,
225 'mime'=>$mime, 226 'mime'=>$mime,
226 'project_id'=>$this->cache['project_id'] ?? 0, 227 'project_id'=>$this->cache['project_id'] ?? 0,
  228 + 'name'=>$name,
227 ]; 229 ];
228 $rs = $imageModel->add($data); 230 $rs = $imageModel->add($data);
229 if ($rs === false) { 231 if ($rs === false) {
@@ -258,6 +260,7 @@ class ImageController extends Controller @@ -258,6 +260,7 @@ class ImageController extends Controller
258 foreach ($files as $file) { 260 foreach ($files as $file) {
259 $imageModel = new ImageModel(); 261 $imageModel = new ImageModel();
260 $hash = hash_file('md5', $file->getPathname()); 262 $hash = hash_file('md5', $file->getPathname());
  263 + $name = $files->getClientOriginalName();
261 //查看图片是否已上传 264 //查看图片是否已上传
262 $param = ['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0]; 265 $param = ['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0];
263 if(isset($this->cache['project_id']) && !empty($this->cache['project_id'])){ 266 if(isset($this->cache['project_id']) && !empty($this->cache['project_id'])){
@@ -279,8 +282,8 @@ class ImageController extends Controller @@ -279,8 +282,8 @@ class ImageController extends Controller
279 $file->move($url,$fileName); 282 $file->move($url,$fileName);
280 } 283 }
281 //批量存储 284 //批量存储
282 - $this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType());  
283 - $data[] = $this->responseData($this->path.'/'.$fileName); 285 + $this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType(),$name);
  286 + $data[] = $this->responseData($this->path.'/'.$fileName,$name);
284 } 287 }
285 $this->response('图片资源',Code::SUCCESS,$data); 288 $this->response('图片资源',Code::SUCCESS,$data);
286 } 289 }
@@ -309,11 +312,11 @@ class ImageController extends Controller @@ -309,11 +312,11 @@ class ImageController extends Controller
309 $this->response('指定图片已被系统删除!', Code::USER_ERROR); 312 $this->response('指定图片已被系统删除!', Code::USER_ERROR);
310 } 313 }
311 } 314 }
312 - $fileName = basename($info['path']); // 要保存的文件名 315 +// $fileName = basename($info['path']); // 要保存的文件名
313 // 设置响应头 316 // 设置响应头
314 header('Content-Description: File Transfer'); 317 header('Content-Description: File Transfer');
315 header('Content-Type: application/octet-stream'); 318 header('Content-Type: application/octet-stream');
316 - header('Content-Disposition: attachment; filename="' . $fileName . '"'); 319 + header('Content-Disposition: attachment; filename="' . $info['name'] . '"');
317 // 下载文件 320 // 下载文件
318 readfile($fileUrl); 321 readfile($fileUrl);
319 } 322 }
@@ -392,10 +395,11 @@ class ImageController extends Controller @@ -392,10 +395,11 @@ class ImageController extends Controller
392 * @method :post 395 * @method :post
393 * @time :2023/7/26 13:41 396 * @time :2023/7/26 13:41
394 */ 397 */
395 - public function responseData($path = ''){ 398 + public function responseData($path = '', $name = ''){
396 $data = [ 399 $data = [
397 'image'=>$path, 400 'image'=>$path,
398 'image_link'=>getImageUrl($path), 401 'image_link'=>getImageUrl($path),
  402 + 'name'=>$name,
399 ]; 403 ];
400 return $data; 404 return $data;
401 } 405 }
@@ -413,7 +417,7 @@ class ImageController extends Controller @@ -413,7 +417,7 @@ class ImageController extends Controller
413 if ($info === false) { 417 if ($info === false) {
414 $this->response('指定文件不存在!', Code::USER_ERROR); 418 $this->response('指定文件不存在!', Code::USER_ERROR);
415 } 419 }
416 - $data = ['image_download'=>url('a/download_images?path='.$info['path'])]; 420 + $data = ['image_download'=>url('a/download_images?path='.$info['path']), 'name' => $info['name']];
417 $this->response('success',Code::SUCCESS,$data); 421 $this->response('success',Code::SUCCESS,$data);
418 } 422 }
419 } 423 }