Page 1 of 1

pdf download problems

Posted: Tue Oct 05, 2010 1:54 pm
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?

Re: pdf download problems

Posted: Tue Oct 05, 2010 5:34 pm
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.

Re: pdf download problems

Posted: Wed Oct 06, 2010 9:53 am
by mc1392
Since I was dealing with Cascade Server, I just placed the file download code in a separate file.
Now it works.