作者 lyh

gxdemo脚本

... ... @@ -64,13 +64,16 @@ class FileManageController extends BaseController
*/
public function downLoad()
{
if(!isset($this->param['path']) || empty($this->param['path'])){
$this->response('参数错误',Code::SYSTEM_ERROR);
// 检查参数
if (!isset($this->param['path']) || empty($this->param['path'])) {
$this->response('参数错误', Code::SYSTEM_ERROR);
}
// 获取文件名和 URL
$username = basename($this->param['path']);
$parsed_url = parse_url($this->param['path']);
if(isset($parsed_url['scheme'])){
$fileUrl = $this->param['path'];
$fileUrl = isset($parsed_url['scheme'])
? $this->param['path']
: 'https://file.globalso.com' . $this->param['path'];
// 获取文件头信息
$headers = get_headers($fileUrl, 1);
if ($headers === false || !isset($headers['Content-Length'])) {
... ... @@ -93,7 +96,7 @@ class FileManageController extends BaseController
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 18192); // 设置缓冲区大小
curl_setopt($ch, CURLOPT_BUFFERSIZE, 8192); // 设置缓冲区大小
curl_setopt($ch, CURLOPT_TIMEOUT, 300); // 设置超时时间
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
... ... @@ -118,15 +121,6 @@ class FileManageController extends BaseController
}
curl_close($ch);
exit;
} else {
$fileUrl = 'https://file.globalso.com'.$this->param['path'];
// 设置响应头
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $username . '"');
// 下载文件
readfile($fileUrl);
}
}
... ...