我正在尝试为PDF文件创建下载链接。如果安装了Adobe Reader,它可以正常工作,但是如果我卸载它,它会尝试在浏览器中打开并失败。
请告诉我这个实际问题是什么?
先谢谢。
答案 0 :(得分:1)
问题是,当安装了adobe reader时,自动获取.pdf文件的标题并显示该文件。
你可以使用它。它总是会提示下载文件..
$path="uploads/";
$actualfilename=$path.$row["name"];
//name of the file or location of file..
if($typeofview=="download") {
@readfile($actualfilename);
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="' . $actualfilename. '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($actualfilename));
header('Accept-Ranges: bytes');
exit;
}
答案 1 :(得分:0)
这是此question的副本,但答案如下:
$path_to_file = '/var/www/somefile.pdf'; //Path to file you want downloaded
$file_name = "somefile.pdf"; //Name of file for download
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="'.$file_name.'"');
header('Content-Transfer-Encoding: binary');
readfile($path_to_file);
die();