downloading text file from mysql blob

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mc1392
Forum Newbie
Posts: 4
Joined: Fri Oct 01, 2010 2:19 pm

downloading text file from mysql blob

Post by mc1392 »

All,

I am successfully downloading pdf and word docs from mysql. When I try to download a text file I get:
Cannot modify header information - headers already sent by ...

here is the code:

Code: Select all

$download = "select data, mimeType, filename from minutes where minutesId='".$id."'";
   
$downloadResult = @mysql_query($download);
    
    
if($row = @mysql_fetch_array($downloadResult)){
$data = @mysql_result($downloadResult, 0, "data");
$mimeType = @mysql_result($downloadResult, 0, "mimeType");
$fileName = $_GET['filename'];

header("Content-type: $mimeType");
header("Content-Disposition: inline; filename=$fileName");
any ideas how to download text files?
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: downloading text file from mysql blob

Post by yacahuma »

remove the header lines and verify the output. something in your code is causing characters to be sent before the header.
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: downloading text file from mysql blob

Post by DigitalMind »

I would remove @
mc1392
Forum Newbie
Posts: 4
Joined: Fri Oct 01, 2010 2:19 pm

Re: downloading text file from mysql blob

Post by mc1392 »

This solved the problem.

Code: Select all

$download = "select data, mimeType, filename from minutes where minutesId='".$id."' and length(trim(filename))>0 and data is not null";
$downloadResult = @mysql_query($download);


	if($row = @mysql_fetch_array($downloadResult)){
		$data = @mysql_result($downloadResult, 0, "data");
		$mimeType = @mysql_result($downloadResult, 0, "mimeType");
		$fileName = $_GET['filename'];

		


		header("Content-type: $mimeType");
		header("Content-Disposition: attachment; filename=$fileName");
		header("Content-type: application/force-download");
		
		echo $data;
		exit;

Post Reply