【发布时间】:2014-03-16 17:24:51
【问题描述】:
我想下载一个 PDF 文件:
$output = RP_MAIN . 'docbook/data/myfile' . $_SESSION["sess_code_user"] . '.pdf'; // this is the pdf file I want to download
$file_size = filesize($output);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-type: text/enriched");
header("Content-length: $file_size");
header('Content-Disposition: attachment; filename="'.'manuel.'. $extension .''.'"');
ob_clean();
flush();
print($output);
exit();
PDF 文件存在于系统中,大小为 25 Kb。但问题是下载弹出窗口(Internet Download Manager)在大小字段中有一个空白字段。
我的代码有什么问题?我该如何解决这个问题?
编辑: pdf 文件是从 ajax 调用创建的,然后在 ajax 成功后开始下载:
var request = $.ajax({
data: donne,
type: "POST",
url: "<?php echo HTTP_AJAX_TACHE ?>TacheCreerPdfAjax.php" , // this creates the pdf file
async: false
});
request.done(function() {
$('#corps').html(request.responseText);
if(fichier == "pdf" || fichier == "rtf")
window.location.href = '<?php echo PAGE_TACHE ?>?action=TacheGenererManuelExec&fichier=' + fichier ; // this starts the download
...
}
所以在启动下载时会出现一个错误,指出源格式不是pdf!
【问题讨论】:
标签: php http-headers download