PHP客户端浏览器下载

时间:2013-07-16 14:27:54

标签: php

我给了PDF的精确文件路径,PDF也没有任何中断下载。但在“退出”后删除出口。 PDF没有下载没有发生。退出功能后我正在做一些处理。

header('Content-Description: File Transfer');
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename='.$pdf_filename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
readfile($file);
session_regenerate_id();
exit;

1 个答案:

答案 0 :(得分:0)

我相信下面的代码会对你有用,但首先删除exit然后在末尾刷新输出并在顶部添加ignore user abort并在刷新后继续处理。

ignore_user_abort(true);
//your code of force download using php readfile
ob_end_flush();
flush();
//code after flushing the output