Hello,
I’m trying to use the following code (download.php)
[code]<?php
//header(‘Content-type: application/pdf’);
if(isset($_GET[‘id’]))
{
include ‘config.php’;
include ‘opendb.php’;
$id = $_GET[‘id’];
$query = "SELECT name, type, size, content " .
“FROM upload WHERE id = ‘$id’”;
$result = mysql_query($query) or die(‘Error, query failed’);
list($name, $type, $size, $content)=mysql_fetch_array($result);
header(“Content-length: $size”);
header(“Content-type: $type”);
header(“Content-Disposition: attachment; filename=$name”);
echo $content;
include ‘closedb.php’;
exit;
}
?>[/code]
to download a file from a mysql database. When I specify the id by putting download.php?id=1, what should be a pdf comes out as
%PDF-1.6 %???? 4 0 obj <> endobj xref 4 104 0000000016 00000 n 0000002710 00000 n 0000012979 00000 n 0000013364 00000 n 0000013505 00000 n 0000013773 00000 n 0000013909 00000 n 0000014057 00000 n 0000014201 00000 n 0000014348 00000 n 0000014490 00000 n 0000014637 00000 n 0000014780 00000 n 0000014982 00000 n 0000015334 00000 n 0000015564 00000 n 0000015641 00000 n 0000015999 00000 n 0000016235 00000 n 0000016443 00000 n 0000016796 00000 n 0000017027 00000 n 0000017386 00000 n 0000017623 00000 n 0000017831 00000 n 0000018184 00000 n 0000018415 00000 n 0000018774 00000 n 0000019011 00000 n 0000019219 00000 n 0000019572 00000 n 0000019803 00000 n 0000020162 00000 n 0000020399 00000 n 0000020607 00000 n 0000020960 00000 n 0000021191 00000 n 0000021550 00000 n 0000021787 00000 n 0000021995 00000 n 0000022348 00000 n 0000022579 00000 n 0000022938 00000 n 0000023175 00000 n 0000023382 00000 n 0000023735 00000 n 0000023966 00000 n 0000024325 00000 n 0000024562 00000 n 0000024769 00000 n 0000025122 00000 n 0000025353 00000 n 0000025712 00000 n 0000025949 00000 n 0000026156 00000 n 0000026509 00000 n 0000026740 00000 n 0000027099 00000 n 0000027336 00000 n 0000027544 00000 n 0000027897 00000 n 0000028128 00000 n 0000028487 00000 n 0000028724 00000 n 0000028863 00000 n 0000029004 00000 n 0000029148 00000 n 0000029287 00000 n 0000029425 00000 n 0000029564 00000 n 0000029707 00000 n 0000029851 00000 n 0000029994 00000 n 0000030138 00000 n 0000030283 00000 n 0000030427 00000 n 0000030566 00000 n 0000030706 00000 n 0000030846 00000 n 0000030985 00000 n 0000031123 00000 n 0000031330 00000 n 0000031683 00000 n 0000031914 00000 n 0000032273 00000 n 0000032510 00000 n 0000032681 00000 n 0000032983 00000 n 0000033073 00000 n 0000034265 00000 n 0000034374 00000 n 0000034451 00000 n 0000037650 00000 n 0000040946 00000 n 0000044211 00000 n 0000047422 00000 n 0000050865 00000 n 0000054175 00000 n 0000057566 00000 n 0000060360 00000 n 0000060450 00000 n 0000060545 00000 n 0000060611 00000 n 0000002376 00000 n trailer <<210C6359FB573646A30EFA6359E23F2E>]>> startxref 0 %%EOF 107 0 obj <>stream x?b``He`0b†]? ???Y8?0`???IM*3082??0??lpg5?gU?eU???(??#°???W???~!†eB kpp? ?‡??¬?–?, ?X>Q?a/– ?@??,? ’n: g?N?i8?????«&H2>`d B??†d,la????„D‡N1™J???3?2»??XZl.???|§^u??{2®n.}#±)dm?••“W???¤?9??U?8?o??A?a y? ?…?4??&?‹?e? endstream endobj 5 0 obj </M
etc, etc.
I know the problem is that the browser is not getting the content-type via this line
header("Content-type: $type");
because if I uncomment this line
//header('Content-type: application/pdf');
everything works fine.
Any help would be much appreciated.
-Robert