Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php,mysql and pdf files

Status
Not open for further replies.

999000333

Programmer
Nov 20, 2006
39
Hello I have the following problem. I create pdf files dinamically and I insert into my database mysql using the following code:

$file = "file.pdf";
$contents = file_get_contents($file);
mysql_query("Insert into table set pdfcontents = '".mysql_escape_string($contents)."'");

When I open the file I see this .. ÛfÏŽ‹3Å‹Ž}`†ýç¼o> endobj 6 0 obj <> stream xœ}SÁŽ›0½ç+Þ©ÛÖ Øã6m•^º]EU¯8t*c

Can anyone tell me how to fix this problem ? is there a particular way of retrive the pdf file stored in my database and see it properly?

One thing I have to say is that the pdf I create they have the same name but different content.

Thank you
 
How are you opening and looking at the file after inserting it into the DB?



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
here how I call it:

$row_ElencoPreventivi is the query variable, that contains all the info of the database

$pdfFile= $row_ElencoPreventivi['pdfcontents'];

<td valign="top" class="<?php echo $Class; ?>">&nbsp;&nbsp;<?php echo "<a href=\"$pdfFile\" target=\"_blank\"><img src=\"./images/ico_pdf.gif\" border=\"0\"></a> \n <br/>"; ?> </td>
Thank you..
Paola
 
and do you expect the pdf file just to show its contents nicely formatted in the table cell?

if so, why? what you are getting is the actual byte contents of the pdf which is programmatically what you are after.

if you want just the formatted contents you will have to use an iframe with the appropriate content-type headers.
 
Hey... thank you for the suggestion... from my question is clear that I don't know a lot about php...can you please be so kind to tell me where can I find more information on this issue? do you know on any website that explain more this particular topic?
Thanks
 
Hi

The problem is not with your PHP knowledge, as this is not a PHP issue. It is pure HTTP & HTML.

The response sent by the web server to the user agent has two parts :
[ol]
[li]HTTP header[/li]
[li]data[/li]
[/ol]
And from this point forward there is no chance for your theory to work because :
[ul]
[li]you can send only one data in each response[/li]
[li]the surrounding HTML document needs header specifying text/html content type, while for the PDF document the content type has to be application/pdf[/li]
[/ul]
To send the PDF separately but to appear in the middle of the HTML document, jpadie already gave you the answer : [tt]iframe[/tt].

Feherke.
 
In other words, you need to supply the appropriate headers to the web page, to get the PDF file to be shown correctly.

Here have a read of this thread.
thread434-1363126


You'll probably have to link to another php page, and have that page generate the PDf file for viewing. Instead of linking directly to the output of the Db as you are doing.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thank you both for the help..... I fix it and it's working!!

Thank you again....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top