作者 赵彬吉

update

... ... @@ -110,7 +110,7 @@ class GoogleSpeedApi
try {
if($url){
$params = [
'url' => $url
'url' => base64_encode($url)
];
$res = HttpUtils::get('http://pagespeed.quanqiusou.cn/api.php', $params);
if ($res) {
... ...
... ... @@ -110,11 +110,12 @@ class FileController
*/
public function single(&$files){
$hash = hash_file('md5', $files->getPathname());
$name = $files->getClientOriginalName();
//查看文件是否存在
$fileModel = new File();
$file_hash = $fileModel->read(['hash'=>$hash]);
if($file_hash !== false){
return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path']));
return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path'], $name));
}
$url = $this->config['root'].$this->path;
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
... ... @@ -128,8 +129,8 @@ class FileController
return $this->response($files->getError(), Code::USER_ERROR);
}
}
$this->saveMysql($fileModel,$files->getSize(),$files->getClientOriginalExtension(),$fileName,$hash,$this->upload_location,$files->getMimeType());
return $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));
$this->saveMysql($fileModel,$files->getSize(),$files->getClientOriginalExtension(),$fileName,$hash,$this->upload_location,$files->getMimeType(),$name);
return $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
}
/**
... ... @@ -139,7 +140,7 @@ class FileController
* @method :post
* @time :2023/7/19 16:38
*/
public function saveMysql(&$fileModel,$size,$image_type,$fileName,$hash,$is_cos = 0,$mime = ''){
public function saveMysql(&$fileModel,$size,$image_type,$fileName,$hash,$is_cos = 0,$mime = '',$name=''){
$data = [
'path' => $this->path.'/'.$fileName,
'created_at' => date('Y-m-d H:i:s',time()),
... ... @@ -149,6 +150,7 @@ class FileController
'refer'=>$this->param['refer'] ?? 1,
'is_cos'=>$is_cos,
'mime'=>$mime,
'name'=>$name,
];
$rs = $fileModel->add($data);
if ($rs === false) {
... ... @@ -168,10 +170,11 @@ class FileController
$data = [];
foreach ($files as $file) {
$fileModel = new File();
$name = $file->getClientOriginalName();
$hash = hash_file('md5', $file->getPathname());
$file_hash = $fileModel->read(['hash'=>$hash]);
if($file_hash !== false){
$data[] = $this->responseData($file_hash['path']);
$data[] = $this->responseData($file_hash['path'], $name);
continue;
}
$url = $this->config['root'].'/'.$this->path;
... ... @@ -189,8 +192,8 @@ class FileController
}
$size = $file->getSize();
$mime = $file->getMimeType();
$this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime);
$data[] = $this->responseData($this->path.'/'.$fileName);
$this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime,$name);
$data[] = $this->responseData($this->path.'/'.$fileName, $name);
}
$this->response('资源',Code::SUCCESS,$data);
}
... ... @@ -230,11 +233,11 @@ class FileController
$this->response('指定文件不存在!', Code::USER_ERROR);
}
$fileUrl = getFileUrl($info['path'],$info['is_cos']);
$fileName = basename($fileUrl); // 要保存的文件名
// $fileName = basename($fileUrl); // 要保存的文件名
// 设置响应头
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
header('Content-Disposition: attachment; filename="' . $info['name'] . '"');
// 下载文件
readfile($fileUrl);
}
... ... @@ -277,7 +280,7 @@ class FileController
}
$this->map['refer'] = 1;
$fileModel = new File();
$lists = $fileModel->list($this->map,'id',['id','hash','type','path','created_at']);
$lists = $fileModel->list($this->map,'id',['id','hash','type','path','created_at','name']);
foreach ($lists as $k => $v){
$v['file_link'] = getFileUrl($v['path']);
$lists[$k] = $v;
... ... @@ -292,10 +295,11 @@ class FileController
* @method :post
* @time :2023/7/26 13:41
*/
public function responseData($path){
public function responseData($path, $name){
$data = [
'file'=>$path,
'file_link'=>getFileUrl($path,$this->upload_location),
'name'=>$name,
];
return $data;
}
... ... @@ -313,7 +317,7 @@ class FileController
if ($info === false) {
$this->response('指定文件不存在!', Code::USER_ERROR);
}
$data = ['file_download'=>url('a/download_files?path='.$info['path'])];
$data = ['file_download'=>url('a/download_files?path='.$info['path']), 'name' => $info['name']];
$this->response('success',Code::SUCCESS,$data);
}
}
... ...
... ... @@ -180,6 +180,7 @@ class ImageController extends Controller
*/
public function single(&$files){
$hash = hash_file('md5', $files->getPathname());
$name = $files->getClientOriginalName();
//查看文件是否存在
$imageModel = new ImageModel();
//查看图片是否已上传
... ... @@ -189,7 +190,7 @@ class ImageController extends Controller
}
$image_hash = $imageModel->read($param);
if($image_hash !== false){
return $this->response('图片资源',Code::SUCCESS,$this->responseData($image_hash['path']));
return $this->response('图片资源',Code::SUCCESS,$this->responseData($image_hash['path'], $name));
}
//保存路径
$url = $this->config['root'].$this->path;
... ... @@ -202,8 +203,8 @@ class ImageController extends Controller
}else{
$files->move($url,$fileName);
}
$this->saveMysql($imageModel,$files->getSize(),$image_type,$fileName,$hash,$this->upload_location,$files->getMimeType());
return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));
$this->saveMysql($imageModel,$files->getSize(),$image_type,$fileName,$hash,$this->upload_location,$files->getMimeType(), $name);
return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
}
/**
... ... @@ -213,7 +214,7 @@ class ImageController extends Controller
* @method :post
* @time :2023/7/19 16:38
*/
public function saveMysql(&$imageModel,$size,$image_type,$fileName,$hash,$is_cos = 0,$mime = ''){
public function saveMysql(&$imageModel,$size,$image_type,$fileName,$hash,$is_cos = 0,$mime = '', $name=''){
$data = [
'path' => $this->path.'/'.$fileName,
'created_at' => date('Y-m-d H:i:s',time()),
... ... @@ -224,6 +225,7 @@ class ImageController extends Controller
'is_cos'=>$is_cos,
'mime'=>$mime,
'project_id'=>$this->cache['project_id'] ?? 0,
'name'=>$name,
];
$rs = $imageModel->add($data);
if ($rs === false) {
... ... @@ -258,6 +260,7 @@ class ImageController extends Controller
foreach ($files as $file) {
$imageModel = new ImageModel();
$hash = hash_file('md5', $file->getPathname());
$name = $files->getClientOriginalName();
//查看图片是否已上传
$param = ['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0];
if(isset($this->cache['project_id']) && !empty($this->cache['project_id'])){
... ... @@ -279,8 +282,8 @@ class ImageController extends Controller
$file->move($url,$fileName);
}
//批量存储
$this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType());
$data[] = $this->responseData($this->path.'/'.$fileName);
$this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType(),$name);
$data[] = $this->responseData($this->path.'/'.$fileName,$name);
}
$this->response('图片资源',Code::SUCCESS,$data);
}
... ... @@ -309,11 +312,11 @@ class ImageController extends Controller
$this->response('指定图片已被系统删除!', Code::USER_ERROR);
}
}
$fileName = basename($info['path']); // 要保存的文件名
// $fileName = basename($info['path']); // 要保存的文件名
// 设置响应头
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
header('Content-Disposition: attachment; filename="' . $info['name'] . '"');
// 下载文件
readfile($fileUrl);
}
... ... @@ -392,10 +395,11 @@ class ImageController extends Controller
* @method :post
* @time :2023/7/26 13:41
*/
public function responseData($path = ''){
public function responseData($path = '', $name = ''){
$data = [
'image'=>$path,
'image_link'=>getImageUrl($path),
'name'=>$name,
];
return $data;
}
... ... @@ -413,7 +417,7 @@ class ImageController extends Controller
if ($info === false) {
$this->response('指定文件不存在!', Code::USER_ERROR);
}
$data = ['image_download'=>url('a/download_images?path='.$info['path'])];
$data = ['image_download'=>url('a/download_images?path='.$info['path']), 'name' => $info['name']];
$this->response('success',Code::SUCCESS,$data);
}
}
... ...