fix(export): 修复Excel导出zipstream库PHP8兼容性与临时文件安全流式输出
这个提交包含在:
@@ -181,6 +181,9 @@ class Export
|
||||
$result = [
|
||||
'file_path' => str_replace(ROOT_PATH, '项目目录/', $save_file)
|
||||
];
|
||||
|
||||
$writer = new $class_name($spreadsheet);
|
||||
$writer->save($save_file);
|
||||
} else {
|
||||
$save_file = $fileName . '-' . date('YmdHis') . '.xlsx';
|
||||
|
||||
@@ -188,20 +191,37 @@ class Export
|
||||
'file_name' => $save_file
|
||||
];
|
||||
|
||||
// 优先安全写入临时文件,确保 Excel 结构与数据完整无误后再输出下载头
|
||||
$tempDir = RUNTIME_PATH . 'temp/export/';
|
||||
if (!is_dir($tempDir)) {
|
||||
@mkdir($tempDir, 0755, true);
|
||||
}
|
||||
$tempFile = $tempDir . 'exp_' . md5(uniqid((string)mt_rand(), true)) . '.xlsx';
|
||||
|
||||
$writer = new $class_name($spreadsheet);
|
||||
$writer->save($tempFile);
|
||||
|
||||
if (!file_exists($tempFile) || filesize($tempFile) <= 0) {
|
||||
@unlink($tempFile);
|
||||
error_stop('生成导出文件失败,请检查数据完整性');
|
||||
}
|
||||
|
||||
if (ob_get_level() > 0) {
|
||||
@ob_end_clean();
|
||||
}
|
||||
header('pragma:public');
|
||||
header("Content-type:application/octet-stream; charset=utf-8; name=" . urlencode($save_file));
|
||||
header("Content-Disposition:attachment; filename=" . urlencode($save_file)); //attachment新窗口打印inline本窗口打印
|
||||
|
||||
$save_file = 'php://output';
|
||||
}
|
||||
|
||||
$writer = new $class_name($spreadsheet);
|
||||
$writer->save($save_file);
|
||||
$fileSize = filesize($tempFile);
|
||||
header('Pragma: public');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
header("Content-Disposition: attachment; filename=" . urlencode($save_file) . "; filename*=utf-8''" . urlencode($save_file));
|
||||
header('Content-Length: ' . $fileSize);
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
|
||||
readfile($tempFile);
|
||||
@unlink($tempFile);
|
||||
|
||||
if ($this->config['save_type'] != 'save') {
|
||||
if (function_exists('fastcgi_finish_request')) {
|
||||
fastcgi_finish_request();
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户