Retrieving a PDF file from a MSSQL data base with php

Posted on 2003-03-01
Medium Priority
Last Modified: 2013-12-13
Here my code:

 //connect data base and select the table....
 $SQuery = "select len,pdfdata from PDFTable where nid = 34"
 // the entry exist
 // fetch the only row
 $row = mssql_fecth_row($SQuery);
 // ok!!
 header("Content-type: application/pdf");
 header("Content-lenght: ".$row[0]);
 print $row[1];

 The script launch the PDF program, but it remains in the list of process getting the 100% of the CPU.
 I think that the data are not completed, due to when i delete the headers lines, the binary code appears into the browser, but is not complete!!!, i think only it show 4096 bytes of the file instead of the 65470 of its real lenght.....

I did the same test using ASP .NET and the code, similar from the above works fine, but i need make it in PHP.
 Any limitations?, any wrong in the php code? or maybe this language script is not ready to work with MSSQL Server?.

Thank´s in advantage.

Question by:elnexus

Expert Comment

ID: 8074010
It's a round about way of fixing it, but others have solved this problem using the DUMPFILE flag in their query.

For your query it would look like:

$SQuery="SELECT len,pdfdata from PDFTable WHERE nid=34 DUMPFILE \"/tmp/temp.pdf\""

Then read in the file and display it.

By the way, if the PDF is 65470 bytes, I assume you are using MEDIUM BLOBs or larger?


Accepted Solution

klewlis earned 800 total points
ID: 8155047
you have Content-lenght instead of Content-length


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question