Solved

Displaying a mysql longblob to a browser, RELIABLY

Posted on 2003-11-29
3
1,784 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 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

13 Experts available now in Live!

Get 1:1 Help Now