下载在屏幕上显示垃圾

时间:2013-09-13 22:36:05

标签: php

我有用于从mysql数据库下载pdf文件的PHP代码。 代码在firefox mozilla和谷歌浏览器中运行良好但在IE 10中没有,它在屏幕上显示垃圾。 我用一些头文件实用程序调试了代码来检查头请求,看来头文件没有发送回用户代理(IE浏览器)它只是空白。

<?php
ob_start();
$company =$_GET['company'];
if(isset($_GET['id']))
{
$id = intval($_GET['id']);
if($id <= 0)
{
die('The ID is invalid!');
}
else
{
$dbLink = new mysqli('localhost', 'sqldata', 'sqldata', 'balhaf');
if(mysqli_connect_errno())
{
die("MySQL connection failed: ". mysqli_connect_error());
}
$query = "SELECT mime, name, size, data FROM $company WHERE id = $id";
$result = $dbLink->query($query);
if($result)
{
if($result->num_rows == 1) {
$row = mysqli_fetch_assoc($result);
$size = $row['size'];
$filename = $row['name'];
$data = $row['data'];
$mime = $row['mime'];
ini_get('zlib.output_compression');
ini_set('zlib.output_compression', 'Off');
header('Content-Type: application/pdf');
while (@ob_end_clean());
header('Content-Disposition: attachment; filename='.($filename));
header('Content-Length:'.($size));
echo $data;
exit();
}
else
{
echo 'Error! No image exists with that ID.';
}
mysqli_free_result($result);
}
else
{
echo "Error! Query failed: <pre>{$dbLink->error}</pre>";
}
mysqli_close($dbLink);
}
}
else
{
echo 'Error! No ID was passed.';
}
?>

0 个答案:

没有答案