|
...
|
...
|
@@ -62,21 +62,18 @@ class FileManageController extends BaseController |
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/28 17:18
|
|
|
|
*/
|
|
|
|
public function downLoad(){
|
|
|
|
public function downLoad()
|
|
|
|
{
|
|
|
|
// 检查参数
|
|
|
|
if (!isset($this->param['path']) || empty($this->param['path'])) {
|
|
|
|
$this->response('参数错误', Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
$username = basename($this->param['path']);
|
|
|
|
$parsed_url = parse_url($this->param['path']);
|
|
|
|
|
|
|
|
// 构造文件 URL
|
|
|
|
if (isset($parsed_url['scheme'])) {
|
|
|
|
$fileUrl = $this->param['path'];
|
|
|
|
} else {
|
|
|
|
$fileUrl = 'https://file.globalso.com' . $this->param['path'];
|
|
|
|
}
|
|
|
|
$fileUrl = isset($parsed_url['scheme'])
|
|
|
|
? $this->param['path']
|
|
|
|
: 'https://file.globalso.com' . $this->param['path'];
|
|
|
|
// 初始化 curl
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $fileUrl);
|
|
...
|
...
|
@@ -86,14 +83,17 @@ class FileManageController extends BaseController |
|
|
|
// 执行 curl 请求
|
|
|
|
$fileContent = curl_exec($ch);
|
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
|
|
|
|
$curlError = curl_error($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
// 检查 HTTP 响应码
|
|
|
|
if ($httpCode != 200 || $fileContent === false) {
|
|
|
|
$this->response('文件下载失败', Code::SYSTEM_ERROR);
|
|
|
|
// 检查 curl 错误或 HTTP 状态码
|
|
|
|
if ($fileContent === false || $httpCode != 200) {
|
|
|
|
$errorMsg = $fileContent === false ? "Curl Error: $curlError" : "HTTP Error: $httpCode";
|
|
|
|
$this->response("文件下载失败 - $errorMsg", Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
// 设置响应头
|
|
|
|
header('Content-Description: File Transfer');
|
|
|
|
header('Content-Type: application/octet-stream');
|
|
|
|
header('Content-Type: ' . ($contentType ?: 'application/octet-stream'));
|
|
|
|
header('Content-Disposition: attachment; filename="' . $username . '"');
|
|
|
|
header('Content-Length: ' . strlen($fileContent));
|
|
|
|
// 输出文件内容
|
|
...
|
...
|
@@ -101,6 +101,7 @@ class FileManageController extends BaseController |
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function upload(Request $request, FileManage $fileManage){
|
|
|
|
$request->validate([
|
|
|
|
'file'=>['required'],
|
...
|
...
|
|