I have problems with my headers. Can somebody please explain to me what i am doing wrong. I would like to retrieve pictures form my database which is stores as binary data
My scripts can be seen below
Warning: Cannot add header information - headers already sent by (output started at e:\programmer\apache group\apache\data\cool\download.php:3) in e:\programmer\apache group\apache\data\cool\download.php on line 17
Warning: Cannot add header information - headers already sent by (output started at e:\programmer\apache group\apache\data\cool\download.php:3) in e:\programmer\apache group\apache\data\cool\download.php on line 18
Warning: Cannot add header information - headers already sent by (output started at e:\programmer\apache group\apache\data\cool\download.php:3) in e:\programmer\apache group\apache\data\cool\download.php on line 19
Warning: Cannot add header information - headers already sent by (output started at e:\programmer\apache group\apache\data\cool\download.php:3) in e:\programmer\apache group\apache\data\cool\download.php on line 20
// open_db.inc //
<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("photo", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
?>
//Show pictures show.php//
<?php
include "open_db.inc";
$sql = "SELECT * FROM binary_data ";
$sql .= "ORDER BY filename ASC";
$result = mysql_query($sql, $db);
$rows = mysql_num_rows($result);
echo "<table>\n";
echo " <tr>\n";
echo " <td>Filename</td>\n";
echo " <td>Type</td>\n";
echo " <td>Size</td>\n";
echo " <td>Description</td>\n";
echo " <td> </td>\n";
echo " </tr>\n";
for ($i = 0; $i < $rows; $i++) {
$data = mysql_fetch_object($result);
// since our script is very small, i'm not going to escape out to html mode here
echo " <tr>\n";
echo " <td>$data->filename</td>\n";
echo " <td>$data->filetype</td>\n";
echo " <td>$data->filesize</td>\n";
echo " <td>" . stripslashes($data->description) . "</td>\n";
echo " <td>( <a href='download.php?id=$data->id'>Download</a> )</td>\n";
echo " </tr>\n";
}
mysql_free_result($result);
mysql_close($db);
?>
//Download pictures download.php //
<?php
if ($id) {
include "open_db.inc";
$sql = "SELECT bin_data, filetype, filename, filesize FROM binary_data WHERE id=$id";
$result = @($sql, $db);
$data = @mysql_result($result, 0, "bin_data");
$name = @mysql_result($result, 0, "filename");
$size = @mysql_result($result, 0, "filesize");
$type = @mysql_result($result, 0, "filetype");
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
print "$data";
}
?>