您好,我的网站上有一些 pdf 文件可供用户下载,但问题是当我们下载这些 pdf 文件并尝试打开 pdf 时出现错误“打开文档时出错。文件已损坏并且可能不能修复”,但相反,这在我的本地系统中运行良好。请指导我,这是我的代码
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);
}
}