我有一个用于下载pdf文件的代码。它正在localhost上正常工作,但是我在托管的godaddy上运行这些代码时遇到错误。 这是代码
<?php
include "connect.inc.php";
if(isset($_GET['id'])) {
$id=$_GET['id'];
$query = "select filename from pdf where id=$id";
$row = mysql_query($query);
if(mysql_num_rows($row)==1){
$query_row=mysql_fetch_assoc($row);
$name=$query_row['filename'];
$path="upload/{$name}";
header('Content-Type: application/pdf');
header('Content-Type: application/octet-stream');
header('Content-Description: File Transfer');
header("Content-Disposition: attachment; filename={$name}");
header('Content-Length: '. filesize($path));
readfile($path);
}
}
?>
输出: %PDF-1.4%ãÏÓ6700 obj&lt;&gt; endobj xref 670 7 0000000016 00000 n 0000000912 00000 n 0000000977 00000 n 0000001122 00000 n 0000001188 00000 n 0000001305 00000 n 0000000436 00000 n预告片&lt;&lt; 97ED15AB8479334F8971D1FF246DC63D&gt;]&gt;&gt; ...
答案 0 :(得分:0)
您有两个Content-Type
标头。下定决心。