Codeigniter pdf文件下载时出错
您好,我的网站上有一些pdf文件,用户可以下载,但问题是,当我们下载这些pdf文件并尝试打开pdf时,我遇到了一个错误“打开文档时出错。文件已损坏,无法修复”,但在我的本地系统中,此操作正常。 请引导我,这是我的密码Codeigniter pdf文件下载时出错,codeigniter,pdf,download,Codeigniter,Pdf,Download,您好,我的网站上有一些pdf文件,用户可以下载,但问题是,当我们下载这些pdf文件并尝试打开pdf时,我遇到了一个错误“打开文档时出错。文件已损坏,无法修复”,但在我的本地系统中,此操作正常。 请引导我,这是我的密码 function download_pdf($parameters) { $final_link = "$parameters"; $path = strtolower($final_link); $file = "$path"; if
function download_pdf($parameters)
{
$final_link = "$parameters";
$path = strtolower($final_link);
$file = "$path";
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
else
{
//echo "file do not exist";
redirect('site/file_does_not_exist');
//$data['main_content'] = 'not_found';
//$this->load->view('includes/template',$data);
}
}
请尝试使用此选项:
...
header('Content-Type: application/pdf');
...
从
并确保文件名的扩展名为“.pdf”
application/pdf: Portable Document Format