Page 1 of 1

fopen() pdf file code being written and not showing pdf file

Posted: Mon Aug 22, 2005 7:35 pm
by chandldj
I am trying to show a pdf file on a page by reading it and writing it to the page (I have my reasons for this versus an embed function or something).

instead of displaying a pdf file, the entire file code is being printed on the screen... how do i fix this???

Code: Select all

<?
header ("Content-Type: application/pdf");

$a = mysql_query($query);
$blah = mysql_fetch_assoc($a);
$case = $blah["caseaddress"];
echo " - case - ";
echo $case;

$case = $path.$case;

$chunksize = 1*(1024*1024); // how many bytes per chunk 
$buffer = ''; 
$handle = fopen($case, 'r+b');
if ($handle === false) 
	{ 
   return false; 
	} 
while (!feof($handle)) 
	{ 
	$buffer = fread($handle, $chunksize); 
	print $buffer; 
	} 
return fclose($handle);
?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Mon Aug 22, 2005 7:41 pm
by feyd
your echo's of case need to be removed.

you can use readfile() too. :)

close, but no cigar

Posted: Mon Aug 22, 2005 7:48 pm
by chandldj
Thanks for your help... can you tell i'm a newbie? hehe

i removed all echo commands from the code...

it printed up differently, but i'm still getting...

-----------------------------------------

%PDF-1.4 %äãÏÒ 3 0 obj <> stream xÚ+ä2P0·4RÈå234³rÀ, m%!......................

-----------------------------------------

just a huge page 'o code :(

any more ideas? i'm not sure if fopen is even the right function or if i'm using it right??? i put in readfile in place of fopen and same problem :(

Posted: Mon Aug 22, 2005 7:58 pm
by feyd
seems like you're not sending the right headers, but you have one of the right headers above it... you could try other pdf headers.. you may need to send a content-length header using filesize()

got it! :)

Posted: Mon Aug 22, 2005 9:20 pm
by chandldj
fyi...

the header was "Content-Type: "

when i put the "T" to lower case it worked... fussy fussy.

Thanks for your help!!!