473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Problem showing PDF file from a MySQL blob field

26
I'm having a problem reading a pdf from a longblob mysql field.
My code works in safari and firefox, but IE6 gives an error of (file could not be written to cache) and IE7 just gives a blank page. This is my code:

[PHP]<?php
if (isset($_GET['fileID']) == false) { header("Location: studentsindex.php"); exit;}
if ($_GET['referrer'] == "papers") { $table = "tbl_pastpapers"; } else {$table = "tbl_subjectmaterial"; }
mysql_select_db($database_conn_LSM, $conn_LSM);
$result=mysql_query("SELECT fileID, filepdf FROM ".$table." WHERE fileID='".$_GET['fileID']."'");
$row=mysql_fetch_assoc($result);
Header( "Content-type: application/pdf");
echo $row['filepdf'];
?>[/PHP]

Any suggestions as to how to adapt this to IE?
Aug 17 '07 #1
8 11567
Atli
5,058 Expert 4TB
I have moved your post into it's own thread in the PHP Forum, where it is more likely to be answered.
Please ask new questions in new threads, rather than posting them in an old one.

Moderator
Aug 18 '07 #2
Atli
5,058 Expert 4TB
I'm having a problem reading a pdf from a longblob mysql field.
My code works in safari and firefox, but IE6 gives an error of (file could not be written to cache) and IE7 just gives a blank page. This is my code:

[PHP]<?php
if (isset($_GET['fileID']) == false) { header("Location: studentsindex.php"); exit;}
if ($_GET['referrer'] == "papers") { $table = "tbl_pastpapers"; } else {$table = "tbl_subjectmaterial"; }
mysql_select_db($database_conn_LSM, $conn_LSM);
$result=mysql_query("SELECT fileID, filepdf FROM ".$table." WHERE fileID='".$_GET['fileID']."'");
$row=mysql_fetch_assoc($result);
Header( "Content-type: application/pdf");
echo $row['filepdf'];
?>[/PHP]

Any suggestions as to how to adapt this to IE?
As PHP is executed server-side, the PHP code itself is not the problem, the output you are sending to the browser is. My guess would be that there is a problem with the headers.
The 'application/pdf' header is recognized by IE as a Acrobat Reader document, but it may require that you send the length of the document.

Try sending the 'Content-length' header and see if that helps.
Expand|Select|Wrap|Line Numbers
  1. header("Content-length: ". strlen($row['filepdf']) )";
  2.  
You may also want to send the PDF document name to the browser, which would be done like this:
Expand|Select|Wrap|Line Numbers
  1. header("Content-Disposition: inline; filename=docname.pdf");
  2.  
Aug 18 '07 #3
erp23
26
I've tried both header lines without success - I still get the cannot write to cache error in IE.
I'm not sure whether the content-disposition filename seems to work, since changing tis to attachement gives me the name of the page rather than the filename with a pdf extension. My code so far is:
[PHP]<?php
if (isset($_GET['fileID']) == false) { header("Location: studentsindex.php"); exit;}
if ($_GET['referrer'] == "papers") { $table = "tbl_pastpapers"; } else {$table = "tbl_subjectmaterial"; }
mysql_select_db($database_conn_LSM, $conn_LSM);
$result=mysql_query("SELECT fileID, filepdf FROM ".$table." WHERE fileID='".$_GET['fileID']."'");
$row=mysql_fetch_assoc($result);
header( "Content-type: application/pdf");
header( "Content-length: ".strlen($row['filepdf'])."");
header( "Content-Disposition: attachment; filename=subject.pdf");
echo $row['filepdf'];
?>[/PHP]

Any suggestions? Would a different display method work (e.g. readfile??) and if so, how would I do it?
Aug 18 '07 #4
pbmods
5,821 Expert 4TB
Heya, ERP.

Is your internet cache set too small? Check your internet settings.
Are you running a secure server (https://)?

Can you load the file in Firefox?
Aug 18 '07 #5
erp23
26
Yes, the file uploads without a problem in Firefox, Safari, Navigator and Opera.

I think you have located the problem - I have been using https for all the members pages. If I disable this, the pdf download works fine in IE. Is there a way around this?
Aug 18 '07 #6
erp23
26
I've added the following two snippets which seem to have fixed the problem...

[PHP]header( "Pragma: private");
header( "Cache-Control: max-age=0"); [/PHP]

is that a reasonable solution?
Aug 18 '07 #7
pbmods
5,821 Expert 4TB
Heya, erp.

This is a problem with Internet Explorer, not your code.

Have a look at this article.
Aug 18 '07 #8
erp23
26
i know - although they say this is only for SP1, the bug is still there in IE7, so the cache corrections will probably still be necessary...
Aug 18 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: John | last post by:
I have over 5000 thumbnail pictures of size 5kb each. I would like to able to load all 5000 pictures and view 50 per page using mysql_data_seek(). I would like to know what are the advantages and...
3
by: Bernard Koninckx | last post by:
Hello everybody, I've configured mySQL as datasource for JBoss. I've a problem, when JBoss automaticaly generate a table for the bean. mySQL send an error. The fields length is too long and a...
0
by: Mark Fisher | last post by:
I cannot seem to store binary data as a BLOB. I used the following to create a table capable of holding a BLOB: CREATE TABLE blob_table ( id INT UNSIGNED NOT NULL AUTO_INCREMENT,...
0
by: mcstayinskool | last post by:
I'm trying to dump a bugzilla installation to a file, then restore it to a different database name (so as to test my db backup system). I use mysqldump to dump it to a file: # mysqldump -u root...
6
by: Pierre-Benoit | last post by:
Hi there, I've a strange problem with ado.net and an Access db. I need to create a little C# app that take the content of "ole object" field and then save it into a file. The problem is that...
7
by: sime | last post by:
Hi, I have a blob field in a mysql database table. I want to copy a blob from one record to another. I am having trouble transferring the data via a php variable. Maybe I need to addslashes or...
5
by: lawrence k | last post by:
I'm a little weak on my basic I/O. Help me out please. Is it right to say that I can just open any file with file(), get it as a string, and then store in a MySql database, in, say, a MediumText...
7
by: greywire | last post by:
So I need to load lots of data into my database. So I discover LOAD DATA INFILE. Great! This little gem loads my CSV in blazing times (compared to parsing the file and doing INSERT for each...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.