Normally, a header problem means there's a space near the beginning and ending PHP lines. However, in my case, there aren't any.
<html>
<head>
<title>Download File From MySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
connection line
//Lists files for download
$query = "SELECT id, name FROM upload";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name) = mysql_fetch_array($result))
{
?>
<a href="get.php?id=<?php echo $id; ?>"> <?php echo $name; ?></a> <br>
<?php
}
}
mysql_close;
?>
</body>
</html>
<?php
if(isset($_GET['id']))
{
// if id is set then get the file with the id from database
connection line
$id = $_GET['id'];
$query = "SELECT name, type, size, content " .
"FROM upload WHERE id = '$id'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;
mysql_close;
exit;
}
?>
What I get when I select the file for download is:
Warning: Cannot modify header information - headers already sent by (output started at get.php:8) in get.php on line 48
Warning: Cannot modify header information - headers already sent by (output started at get.php:8) in get.php on line 49
Warning: Cannot modify header information - headers already sent by (output started at get.php:8) in get.php on line 50
ÿØÿà�JFIF�����ÿíJPhotoshop 3.0�8BIMí Resolution��������������8BIM FX Global Lighting Angle�������x8BIMFX Global Altitude�������8BIMóPrint Flags��� ���������8BIM Copyright Flag������8BIM'Japanese Print Flags���� ��������8BIMõColor Halftone Settings���H�/ff��lff�������/ff��¡™š�������2����Z���������5����-��������8BIMøColor Transfer
Nevermind, fixed