作者 lyh
... ... @@ -35,6 +35,7 @@ class RemainDay extends Command
* @var 暂停的项目
*/
protected $ceaseProjectId = [
47,
354,
378,
649,
... ...
... ... @@ -68,43 +68,58 @@ class FileManageController extends BaseController
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
$fileUrl = isset($parsed_url['scheme'])
? $this->param['path']
: 'https://file.globalso.com' . $this->param['path'];
// 初始化 curl
// 初始化 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_RETURNTRANSFER, false);
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);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 8192); // 设置缓冲区大小
curl_setopt($ch, CURLOPT_TIMEOUT, 60); // 设置超时时间
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // 连接超时时间
// 设置为分块输出
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $data) {
echo $data;
flush(); // 强制刷新缓冲区
return strlen($data);
});
// 检查文件头信息
$headers = get_headers($fileUrl, 1);
if ($headers === false || !isset($headers['Content-Length'])) {
$this->response('无法获取文件信息', Code::SYSTEM_ERROR);
}
// 设置响应头
header('Content-Description: File Transfer');
header('Content-Type: ' . ($contentType ?: 'application/octet-stream'));
header('Content-Type: ' . ($headers['Content-Type'] ?? 'application/octet-stream'));
header('Content-Disposition: attachment; filename="' . $username . '"');
header('Content-Length: ' . strlen($fileContent));
// 输出文件内容
echo $fileContent;
header('Content-Length: ' . $headers['Content-Length']);
header('Cache-Control: must-revalidate');
header('Pragma: public');
// 执行 cURL
ob_end_clean(); // 清空之前的输出缓冲区
curl_exec($ch);
// 检查 cURL 错误
if (curl_errno($ch)) {
curl_close($ch);
$this->response('文件下载失败: ' . curl_error($ch), Code::SYSTEM_ERROR);
}
curl_close($ch);
exit;
}
public function upload(Request $request, FileManage $fileManage){
$request->validate([
'file'=>['required'],
... ...
... ... @@ -692,7 +692,7 @@ class ProductLogic extends BaseLogic
'attrs'=>Arr::a2s($info['attrs']),
'attr_id'=>Arr::arrToSet($info['attr_id']),
'category_id'=>!empty($info['category_id']) ? ','.Arr::arrToSet($info['category_id']).',' : '',
'keyword_id'=>!empty($info['keyword_id']) ? ','.Arr::arrToSet($info['keyword_id']).',' : '',
'keyword_id'=>'',
'intro'=>$info['intro'],
'content'=>$info['content'],
'describe'=>Arr::a2s($info['describe']),
... ...