php脚本下载PDF文件

时间:2015-10-07 04:10:24

标签: php mysql pdf

我正在尝试为数据库中的每个用户创建一个下载链接,以下载他们的每个PDF文件。我使用了以下代码

$sqlh = mysql_query("SELECT * FROM tbl_health", $con) or die(mysql_error());
       $no = 1;
        while($data = mysql_fetch_array($sqlh)){
            $no++;
             $data['link'];
            echo "<a href='view.php?id=" .$data['health_id']. "'>Download</a>";

        }

我的view.php是

if(isset($_GET['id'])){
$sql = mysql_query("SELECT * FROM tbl_health WHERE health_id='".$_GET['id']."'") or die(mysql_error());
echo $_GET['id'];
$data = mysql_fetch_array($sql);
$file = $data['link'];
$name = "health/".$file;
header("Content-Disposition: attachment; filename=". urlencode($file));
header("Content-Type: application/download");
header("Content-Length: ". filesize($name));
$fp = fopen($name, "r");
  //echo fread($fp, 65536);
readfile($fp);

  fclose($fp); }

可以下载pdf,但打开时查看其空白。 请帮忙

0 个答案:

没有答案