如何使用php从mysql数据库下载.pdf文件?

时间:2014-09-08 05:47:49

标签: php mysql pdf

我使用以下代码从mysql数据库下载pdf文件。该代码与localhost完美配合,pdf下载。但是现在当网站上线时,我无法下载该文件。它会在屏幕上抛出一些像这样的字符。这就是

我的代码是:

if (isset($_POST['download']))
{
$Tno2 = $_SESSION['Tno'];
$gotten = @mysql_query("select * from tenders where Tno = '$Tno2'");
$row1 = @mysql_fetch_assoc($gotten);
$bytes = $row1[file];
if (empty($bytes))
  {
    echo "<b>Tender document not available for this tender.</b>";
  }
else
  {
    header("Content-type: application/pdf");
    header('Content-disposition: attachment; filename="Tenderdoc.pdf"');
    print $bytes;
  }
 }

请在我的代码或我可能遗失的任何内容中建议所需的更改。感谢。

1 个答案:

答案 0 :(得分:0)

修改您的问题。你是在数据库中搜索pdf的URL还是在数据库中存储为字节?

如果您要存储为URL,请检查您是否提供有效路径