Page 1 of 1

create a download link in php to a file in mysql blob field

Posted: Sat Jan 03, 2009 6:17 pm
by jetson1
create a download link in php to a file in a mysql blob field

Hi everyone!
I'm new to the board and relatively new to php. I'm trying to setup my website to use php and mysql and I'm having a little trouble. I've got almost everything working at the moment except for creating download links. I want users, regular users from the internet who are not registered etc., to be able to download a sample file from my website. The sample file is a microsoft excel file 2003 or 2007; the file is stored in a blob type field in my mysql database. I've got the file uploaded and everything up to there working. The problem is that I am not sure how to create a download link to this excel file. I want it to be a dynamic download link, since there will be many excel files, which, when clicked, will open the download link to get the file.

So, my problem is that I don't know how to create this link.

I know that I need headers, something like this:

Code: Select all

header("Content-type: application/vnd.ms-excel");
header("Cache-Control: no-cacher, must-revalidate");
header("Expires: Sat, 13 May 1991 01:00:00 GMT");
and that I might also need something like this:

Code: Select all

<?php
 
// open the file in a binary mode
$name = '$row['excelfilel']';
$fp = fopen($name, 'rb');
 
 
 
// dump the picture and stop the script
fpassthru($fp);
exit;
 
?>

But, I'm really not sure how to make this work. Any help in creating this download link to an excel file contained in a blob field in mysql would be greatly appreciated. I'm sure this is probably really easy to do; thanks for your time!

Re: create a download link in php to a file in mysql blob field

Posted: Thu Jan 08, 2009 12:10 am
by novice4eva
Put these two line of code at the top of a php page

Code: Select all

 
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
 
followed by a echo command on your blob content. And on the link where you want to initiate the download, put the link of this file.

Re: create a download link in php to a file in mysql blob field

Posted: Thu Jan 08, 2009 5:17 am
by VladSun
novice4eva wrote:

Code: Select all

header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
PDF? :)

Re: create a download link in php to a file in mysql blob field

Posted: Thu Jan 08, 2009 5:36 am
by novice4eva
Straight copy paste from MANUAL :mrgreen:
Correction

Code: Select all

 
header('Content-Disposition: attachment; filename="myXLS.xls"');