pdf download problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mc1392
Forum Newbie
Posts: 4
Joined: Fri Oct 01, 2010 2:19 pm

pdf download problems

Post by mc1392 »

All, Im using the following to download pdf blobs from mysql:

Code: Select all

$download = "select data, mimeType, filename from minutes where minutesId='".$id."' and length(trim(filename))>0 and data is not null";
$downloadResult = @mysql_query($download);


	if($row = @mysql_fetch_array($downloadResult)){
		$data = @mysql_result($downloadResult, 0, "data");
		$mimeType = @mysql_result($downloadResult, 0, "mimeType");
		$fileName = $_GET['filename'];

		


		header("Content-type: $mimeType");
		header("Content-Disposition: attachment; filename=$fileName");
		header("Content-type: application/force-download");
		
		echo $data;
		exit;

This works on my local desktop retrieving the blob pdf from a remote db. I moved this code to cascade server, on another machine. the pdf is getting posted to the page, not a download box like on my local machine. basically, I see bytes and garbled characters. At first, there was no pdflib extension, so I installed it. Still no good.

Any ideas?
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: pdf download problems

Post by flying_circus »

mc1392 wrote:basically, I see bytes and garbled characters.
Usually an indication that your script is producing output before your headers or pdf data. Atleast, thats been my experience.

Try exit(); just before the header calls and then just after to see if PHP is throwing a notice or error message. You may need to turn error reporting on first.
mc1392
Forum Newbie
Posts: 4
Joined: Fri Oct 01, 2010 2:19 pm

Re: pdf download problems

Post by mc1392 »

Since I was dealing with Cascade Server, I just placed the file download code in a separate file.
Now it works.
Post Reply