|
...
|
...
|
@@ -62,25 +62,49 @@ class FileManageController extends BaseController |
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/28 17:18
|
|
|
|
*/
|
|
|
|
public function downLoad(){
|
|
|
|
if(!isset($this->param['path']) || empty($this->param['path'])){
|
|
|
|
$this->response('参数错误',Code::SYSTEM_ERROR);
|
|
|
|
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']);
|
|
|
|
if(isset($parsed_url['scheme'])){
|
|
|
|
$fileUrl = $this->param['path'];
|
|
|
|
} else {
|
|
|
|
$fileUrl = 'https://file.globalso.com'.$this->param['path'];
|
|
|
|
// 构造文件 URL
|
|
|
|
$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);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
curl_setopt($ch, CURLOPT_HEADER, false);
|
|
|
|
// 跳过 SSL 验证
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
// 执行 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);
|
|
|
|
// 检查 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 . '"');
|
|
|
|
// 下载文件
|
|
|
|
readfile($fileUrl);
|
|
|
|
header('Content-Length: ' . strlen($fileContent));
|
|
|
|
// 输出文件内容
|
|
|
|
echo $fileContent;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function upload(Request $request, FileManage $fileManage){
|
|
|
|
$request->validate([
|
|
|
|
'file'=>['required'],
|
...
|
...
|
|