moorland 发表于 2009-5-5 15:53:05

怎样做到点击一个PDF文件的链接后提示下载保存文件

我的网页上有一个"下载"的按钮, 需要下载的文件是pdf格式的,
我想知道如何做到下载而不是直接打开呢?

多谢

neversaylate 发表于 2009-5-5 16:30:05

<?php$filename = "document.pdf";header('Content-Type: application/octet-stream');header('Content-Disposition: attachment; filename=' . $filename);?>
这样用浏览器打开之后,就可以下载document.pdf。

neversaylate 发表于 2009-5-5 16:36:13

http://www.phpv.net/html/1675.html

moorland 发表于 2009-5-5 16:59:01


这样用浏览器打开之后,就可以下载document.pdf。
neversaylate 发表于 2009-5-5 16:30 http://codeigniter.org.cn/forums/images/common/back.gif

多谢, 真的很好用呢....:victory:

moorland 发表于 2009-5-5 17:59:34

<?php

$filename = "download/simfin.pdf";

$fp   =   fopen($filename,   "r");

header('Content-Type: application/octet-stream');

header('Content-Disposition: attachment; filename=' . $filename);

echo   fread($fp,filesize($filename));
fclose($fp);

?>

两蚊鸡 发表于 2009-5-13 22:33:25

主要是这句“'Content-Disposition: attachment”,了解一下http协议,有很多有趣的东西
页: [1]
查看完整版本: 怎样做到点击一个PDF文件的链接后提示下载保存文件