0

我正在尝试为 PDF 文件创建下载链接。如果安装了 Adob​​e Reader,它可以正常工作,但如果我卸载它,它会尝试在浏览器中打开并失败。

请告诉我这方面的实际问题是什么?

提前致谢。

4

2 回答 2

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;
}
于 2012-09-25T11:15:39.237 回答
0

这是这个问题的副本,但这里是答案:

$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();
于 2012-09-25T12:53:03.270 回答