I've been using this code to show my images
<dd><?php echo '<img src="data:image/jpeg;base64,'.base64_encode( $result['image'] ).'"/>';
But when I want to show an pdf file I get nothing on my page, i only get my the frame from the iframe tag.
I've using this code to show my pdf file (also stored as a blob):
<dt> <?php echo '<iframe src="data:application/pdf;base64,'.base64_encode( $result['image'] ).'"</iframe>'; ?></dt>
There are different possible reasons why you have the problem:
- The data in the database is corrupt
- The retrieval of the data from the database leads to corrupted data
- The HTML you created simply doesn't work in your browser.
To find out the culprit, you can do the following steps:
- Retrieve the PDF-data from the database manually and try to open it in a PDF-reader. If that doesn't work, your PDF-data in the table is most likely corrupt. Check the process saving the data to the database.
- Encode the retrieved data to base64 (check if that was done correctly by decoding it again and open the decoded data in the reader).
- Output the base64 encoded text from you PHP-script and compare the two base64-blocks for equality. If they differ, your script seems to corrupt the data when retrieving the data from the DB.
- Create a static HTML-page, using the base64-data you generated before and open it in a browser. If that doesn't work, your HTML is not correct for embedding PDF into it or the browser simply doesn't support showing PDF embedded.