正在显示
1 个修改的文件
包含
36 行增加
和
34 行删除
| @@ -85,38 +85,38 @@ class FileController | @@ -85,38 +85,38 @@ class FileController | ||
| 85 | // 设置Accept-Ranges头部 | 85 | // 设置Accept-Ranges头部 |
| 86 | $header['Accept-Ranges'] = 'bytes'; | 86 | $header['Accept-Ranges'] = 'bytes'; |
| 87 | // 检查是否有范围请求 | 87 | // 检查是否有范围请求 |
| 88 | - if (isset($_SERVER['HTTP_RANGE'])) { | ||
| 89 | - $range = $_SERVER['HTTP_RANGE']; | ||
| 90 | - $ranges = explode('-', substr($range, 6)); | ||
| 91 | - $start = intval($ranges[0]); | ||
| 92 | - $end = $size - 1; | ||
| 93 | - if (!empty($ranges[1])) { | ||
| 94 | - $end = intval($ranges[1]); | ||
| 95 | - } | ||
| 96 | - $length = $end - $start + 1; | ||
| 97 | - // 设置部分响应头部 | ||
| 98 | - $header['Content-Length'] = $length; | ||
| 99 | - $header['Content-Range'] = 'bytes ' . $start . '-' . $end . '/' . $size; | ||
| 100 | - // 发送206 Partial Content状态码 | ||
| 101 | - header('HTTP/1.1 206 Partial Content'); | ||
| 102 | - header('Status: 206 Partial Content'); | ||
| 103 | - header('Accept-Ranges: bytes'); | ||
| 104 | - header('Content-Range: bytes ' . $start . '-' . $end . '/' . $size); | ||
| 105 | - // 读取部分内容并发送响应 | ||
| 106 | - $file = fopen($path, 'rb'); | ||
| 107 | - fseek($file, $start); | ||
| 108 | - $buffer = 1024 * 8; // 设置缓冲区大小 | ||
| 109 | - while (!feof($file) && ($p = ftell($file)) <= $end) { | ||
| 110 | - if ($p + $buffer > $end) { | ||
| 111 | - // 最后一块缓冲区 | ||
| 112 | - $buffer = $end - $p + 1; | ||
| 113 | - } | ||
| 114 | - echo fread($file, $buffer); | ||
| 115 | - flush(); // 将输出刷新到浏览器 | ||
| 116 | - } | ||
| 117 | - fclose($file); | ||
| 118 | - exit; | ||
| 119 | - } | 88 | +// if (isset($_SERVER['HTTP_RANGE'])) { |
| 89 | +// $range = $_SERVER['HTTP_RANGE']; | ||
| 90 | +// $ranges = explode('-', substr($range, 6)); | ||
| 91 | +// $start = intval($ranges[0]); | ||
| 92 | +// $end = $size - 1; | ||
| 93 | +// if (!empty($ranges[1])) { | ||
| 94 | +// $end = intval($ranges[1]); | ||
| 95 | +// } | ||
| 96 | +// $length = $end - $start + 1; | ||
| 97 | +// // 设置部分响应头部 | ||
| 98 | +// $header['Content-Length'] = $length; | ||
| 99 | +// $header['Content-Range'] = 'bytes ' . $start . '-' . $end . '/' . $size; | ||
| 100 | +// // 发送206 Partial Content状态码 | ||
| 101 | +// header('HTTP/1.1 206 Partial Content'); | ||
| 102 | +// header('Status: 206 Partial Content'); | ||
| 103 | +// header('Accept-Ranges: bytes'); | ||
| 104 | +// header('Content-Range: bytes ' . $start . '-' . $end . '/' . $size); | ||
| 105 | +// // 读取部分内容并发送响应 | ||
| 106 | +// $file = fopen($path, 'rb'); | ||
| 107 | +// fseek($file, $start); | ||
| 108 | +// $buffer = 1024 * 8; // 设置缓冲区大小 | ||
| 109 | +// while (!feof($file) && ($p = ftell($file)) <= $end) { | ||
| 110 | +// if ($p + $buffer > $end) { | ||
| 111 | +// // 最后一块缓冲区 | ||
| 112 | +// $buffer = $end - $p + 1; | ||
| 113 | +// } | ||
| 114 | +// echo fread($file, $buffer); | ||
| 115 | +// flush(); // 将输出刷新到浏览器 | ||
| 116 | +// } | ||
| 117 | +// fclose($file); | ||
| 118 | +// exit; | ||
| 119 | +// } | ||
| 120 | // 无范围请求,发送完整文件 | 120 | // 无范围请求,发送完整文件 |
| 121 | $header['Content-Length'] = $size; | 121 | $header['Content-Length'] = $size; |
| 122 | $content = file_get_contents($path); | 122 | $content = file_get_contents($path); |
| @@ -177,6 +177,7 @@ class FileController | @@ -177,6 +177,7 @@ class FileController | ||
| 177 | //同步数据到cos | 177 | //同步数据到cos |
| 178 | if($this->upload_location == 1){ | 178 | if($this->upload_location == 1){ |
| 179 | $cosService = new CosService(); | 179 | $cosService = new CosService(); |
| 180 | + $is_cos = 1;//上传到cos | ||
| 180 | $cosService->uploadFile($files,$this->path,$fileName); | 181 | $cosService->uploadFile($files,$this->path,$fileName); |
| 181 | }else{ | 182 | }else{ |
| 182 | $res = $files->move($url,$fileName); | 183 | $res = $files->move($url,$fileName); |
| @@ -184,7 +185,7 @@ class FileController | @@ -184,7 +185,7 @@ class FileController | ||
| 184 | return $this->response($files->getError(), Code::USER_ERROR); | 185 | return $this->response($files->getError(), Code::USER_ERROR); |
| 185 | } | 186 | } |
| 186 | } | 187 | } |
| 187 | - $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash); | 188 | + $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$is_cos); |
| 188 | return $this->response('资源',Code::SUCCESS,['file'=>$hash]); | 189 | return $this->response('资源',Code::SUCCESS,['file'=>$hash]); |
| 189 | } | 190 | } |
| 190 | 191 | ||
| @@ -195,7 +196,7 @@ class FileController | @@ -195,7 +196,7 @@ class FileController | ||
| 195 | * @method :post | 196 | * @method :post |
| 196 | * @time :2023/7/19 16:38 | 197 | * @time :2023/7/19 16:38 |
| 197 | */ | 198 | */ |
| 198 | - public function saveMysql(&$fileModel,$size,$image_type,$fileName,$hash){ | 199 | + public function saveMysql(&$fileModel,$size,$image_type,$fileName,$hash,$is_cos = 0){ |
| 199 | $data = [ | 200 | $data = [ |
| 200 | 'path' => $this->path.'/'.$fileName, | 201 | 'path' => $this->path.'/'.$fileName, |
| 201 | 'created_at' => date('Y-m-d H:i:s',time()), | 202 | 'created_at' => date('Y-m-d H:i:s',time()), |
| @@ -203,6 +204,7 @@ class FileController | @@ -203,6 +204,7 @@ class FileController | ||
| 203 | 'hash' => $hash, | 204 | 'hash' => $hash, |
| 204 | 'type'=>$image_type, | 205 | 'type'=>$image_type, |
| 205 | 'refer'=>$this->param['refer'] ?? 1, | 206 | 'refer'=>$this->param['refer'] ?? 1, |
| 207 | + 'is_cos'=>$is_cos | ||
| 206 | ]; | 208 | ]; |
| 207 | $rs = $fileModel->add($data); | 209 | $rs = $fileModel->add($data); |
| 208 | if ($rs === false) { | 210 | if ($rs === false) { |
-
请 注册 或 登录 后发表评论