Solved

Displaying a mysql longblob to a browser, RELIABLY

Posted on 2003-11-29
3
1,829 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use session variables in php? 22 89
WordPress  Failed to Import Media 8 64
Insert PHP into HTML page. 7 50
How would I break down this array? 3 17
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 …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

737 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