?
Solved

Displaying a mysql longblob to a browser, RELIABLY

Posted on 2003-11-29
3
Medium Priority
?
1,846 Views
Last Modified: 2013-12-12
I am trying to retrieve a document from a db, and display it to the browser via a basic php script. It works for many browsers perfectly, (mozilla all the time, IE occasionally)... but for many others it brings up the attachment popup (save/open/cancel) in the browser, and when you click "open", windows complains that it doesn't recognize the document type and/or can't display it.  

I may be using too many, or the wrong type of php header()'s to display the doc.  Can anyone advise on a reliable way to display a longblob to the browser?
Thanks!


// the key mysql db types
  doc longblob,
  doc_name varchar(120),
  doc_size varchar(32),
  doc_type varchar(32),

// sample data, not including the longblob
| kamvar.txt                      | 3384     | text/plain                    |
| columbia_ps.pdf              | 16833    | application/pdf               |
| huiCV_1.pdf                    | 24294    | application/pdf               |
| demopaper.pdf               | 42249    | application/pdf               |

-----------
<?php

openDB('Recruit');

$query = "SELECT d.doc_name, d.doc_size, d.doc_type, d.doc
               FROM Recruit.document d, Recruit.candidate c
               WHERE c.c=d.c AND d.c='$c_id' AND d.doc_id='$f_doc_id'";
$result = query($query);
$row = mysql_fetch_assoc($result);


header("Content-Type: $row[doc_type]");
//header("Cache-control: private");     // do i need this line?  i've tried w/ and w/o
header("Content-Length: $row[doc_size]");
header("Content-Disposition: inline; filename=$row[doc_name]");

echo($row['doc']);

?>
0
Comment
Question by:blinkie23
1 Comment
 
LVL 14

Accepted Solution

by:
ThG earned 640 total points
ID: 9844093
That looks ok, but if you want the browser to open it, drop the content-disposition thing...
also make sure the size respects the actual size. try to see if strlen($row['doc']) equals $row['doc_size']
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
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.
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

839 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