在php

时间:2015-11-25 18:36:53

标签: php mysql

我在使用PHP浏览每个浏览器中的pdf文件时遇到问题。 以下代码是我在PHP中的方式

数据库结构:

CREATE TABLE `upload` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(30) NOT NULL,
  `type` VARCHAR(30) NOT NULL,
  `content` LONGBLOB NOT NULL,
  `size` INT(11) NOT NULL,
  `AppId` INT(11) NOT NULL,
  PRIMARY KEY (`id`)
)

PHP

 <?php
     $id = $_GET['file'];
      $con=mysql_connect("localhost", "root", "root");
        mysql_select_db("nsc");
        If (!$con){
                echo ("Unable to connect to database!");
                  }
        else {
                  $query = "Select * from upload where id = $id";

                  $result = mysql_query($query);
                  $row = mysql_fetch_array($result);
                  $size = $row['size'];
                  $type = $row['type'];
                  $name =$row['name'];

                  header("Content-length: $size)");
                  header("Content-type: $type");
                  header("Content-Type: application/octet-stream");
                  header("Content-Disposition: attachment;                             filename=".basename($name));
                  header('Content-Transfer-Encoding: binary');
                  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                  header('Pragma: public');
               }
              mysql_close($con);

         ?>

有谁知道问题是什么?谢谢。

0 个答案:

没有答案