Opening file stored in blob
Posted: Thu Oct 14, 2010 12:57 pm
I have two different websites that both have a php frontend and mysql database. Both have a page where the user can upload a document which is stored in a table. The content of the file is stored in a blob field. Here is the database table definition.
CREATE TABLE filetable (
ID int(10) NOT NULL auto_increment,
filedata mediumblob NOT NULL,
filedescription varchar(50) default NULL,
filename varchar(50) NOT NULL default '',
filesize varchar(50) NOT NULL default '',
filetype varchar(50) NOT NULL default '',
username varchar(45) NOT NULL default '',
PRIMARY KEY (ID)
) TYPE=MyISAM AUTO_INCREMENT=131 ;
I am able to upload a pdf or word or xls file to the page using some php code for file uploading. It is the same on both websites.
Now for my issue. I have a page where the files from the database are displayed and provide link for the user to open the file. The issue is that the code works on one site but not the other. The only difference I can tell you is the one that works is running php 4.0 and the one that doesn't work is running 5.0
Is there a change in the way 5.0 is executing this code. It is identical on both
This is the code executed when they click on the "view or download" link.
CREATE TABLE filetable (
ID int(10) NOT NULL auto_increment,
filedata mediumblob NOT NULL,
filedescription varchar(50) default NULL,
filename varchar(50) NOT NULL default '',
filesize varchar(50) NOT NULL default '',
filetype varchar(50) NOT NULL default '',
username varchar(45) NOT NULL default '',
PRIMARY KEY (ID)
) TYPE=MyISAM AUTO_INCREMENT=131 ;
I am able to upload a pdf or word or xls file to the page using some php code for file uploading. It is the same on both websites.
Now for my issue. I have a page where the files from the database are displayed and provide link for the user to open the file. The issue is that the code works on one site but not the other. The only difference I can tell you is the one that works is running php 4.0 and the one that doesn't work is running 5.0
Is there a change in the way 5.0 is executing this code. It is identical on both
Code: Select all
<?php
if ($id) {
include ("dbconnect.inc.php");
$sql = "SELECT * FROM filetable WHERE ID=$id";
$result = mysql_query($sql);
$result = mysql_fetch_object($result);
$username = $_COOKIE["user"];
header("Content-type: $result->filetype");
header("Content-length: $result->filesize");
header("Content-Disposition: attachment; filename=$result->filename");
header("Content-Description: PHP Generated Data");
echo $result->filedata;
}
?>