Solved

Displaying a mysql longblob to a browser, RELIABLY

Posted on 2003-11-29
3
1,799 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
3 Comments
 
LVL 14

Accepted Solution

by:
ThG earned 160 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now