Forum Moderators: coopster

Message Too Old, No Replies

Warning: Cannot modify header information - headers already sent

         

imagined

10:02 pm on Apr 1, 2004 (gmt 0)

10+ Year Member



I'm doing this page so files can be downloaded. They will have different file types, that's why I use the file type as a variable.

It gives me this error message = Warning: Cannot modify header information - headers already sent by (output started at C:\apache\Apache2\htdocs\JAVASCRIPT\downloadfile.php:4) in C:\apache\Apache2...

SHOWFILES.PHP

<>html>
<head>
<title> Show Files </title>
<?php include("connection.php");?>
</head>
<body bgcolor="#FFFFFF">
<?php

$dbQuery = "SELECT blobId, blobTitle, blobType ";
$dbQuery .= "FROM myBlobs ";
$dbQuery .= "ORDER BY blobTitle ASC";
$result = mysql_query($dbQuery) or die("Couldn't get file list");
?>

<bunch of html output>

</font>
</td><td width="33%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10"><font face="Verdana" size="1">
<a href="downloadfile.php?blobId=<?php echo $row["blobId"];?>">
Download now
</a></font>
</td></tr>

<?php
}
echo "</table>";
?>

</body>
</html>

DOWNLOADFILES.PHP

<html>
<head>
<title> Download File </title>
<?php
include("connection.php");
global $blobId;
if(!is_numeric($blobId))
die("Invalid blobId specified");

?>
</head>
<body bgcolor="#FFFFFF">
<?php

$dbQuery = "SELECT blobType, blobData ";
$dbQuery .= "FROM myBlobs ";
$dbQuery .= "WHERE blobId = $blobId";
$result = mysql_query($dbQuery) or die("Couldn't get file list");

if(mysql_num_rows($result) == 1)
{
$fileType = @mysql_result($result, 0, "blobType");
$fileContent = @mysql_result($result, 0, "blobData");

header('Content-Type: ' . $fileType);
echo $fileContent;
}

else
{
echo "Record doesn't exist.";
}
?>

</body>
</html>

THANKS FOR YOUR TIME!

[edited by: jatar_k at 11:33 pm (utc) on April 2, 2004]
[edit reason] reduced code [/edit]

bofe

1:11 am on Apr 2, 2004 (gmt 0)

10+ Year Member



You'll want to take a look at output buffering.

[us2.php.net...]

mykel79

10:55 am on Apr 2, 2004 (gmt 0)

10+ Year Member



Headers can only be sent if nothing has been sent to the browser yet. So, like bofe said - either buffer the output somehow, or just move the
<html>
<head>
.
.

below header(...)