Page 1 of 1

downloading text file from mysql blob

Posted: Fri Oct 01, 2010 2:24 pm
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?

Re: downloading text file from mysql blob

Posted: Fri Oct 01, 2010 3:06 pm
by yacahuma
remove the header lines and verify the output. something in your code is causing characters to be sent before the header.

Re: downloading text file from mysql blob

Posted: Fri Oct 01, 2010 3:08 pm
by DigitalMind
I would remove @

Re: downloading text file from mysql blob

Posted: Tue Oct 05, 2010 1:50 pm
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;