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
mc1392
Forum Newbie
Posts: 4 Joined: Fri Oct 01, 2010 2:19 pm
Post
by mc1392 » Fri Oct 01, 2010 2:24 pm
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?
yacahuma
Forum Regular
Posts: 870 Joined: Sun Jul 01, 2007 7:11 am
Post
by yacahuma » Fri Oct 01, 2010 3:06 pm
remove the header lines and verify the output. something in your code is causing characters to be sent before the header.
DigitalMind
Forum Contributor
Posts: 152 Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov
Post
by DigitalMind » Fri Oct 01, 2010 3:08 pm
I would remove @
mc1392
Forum Newbie
Posts: 4 Joined: Fri Oct 01, 2010 2:19 pm
Post
by mc1392 » Tue Oct 05, 2010 1:50 pm
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;