Solved

Displaying a mysql longblob to a browser, RELIABLY

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
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…
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…
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 …

707 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