Hi everyone,
can you check for me if my codes below are correct? i am having problem to retrieve my image file from mysql database. The errors start at "header" parts. I have no problem to store image file (mediumblob) in mysql database. The file shown are in HEX forms.
**********************************************************
<html>
<head>
<title>Download File From MySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$a = mysql_connect("localhost","root","");
if (!$a){
die ("<br>ERROR in mysql_connect<br>");
} else
$db = mysql_select_db('test');
$query = "SELECT * FROM image";
echo " <br> line 16..... <br>";
$result = mysql_query($query) or die('Error, line 17 query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name) = mysql_fetch_array($result))
{
echo " <br> line 25..... <br>";
echo "<a href=\"download.php?id=$id \"></a> <br>";
echo "line 31......";
}
}
mysql_close();
?>
</body>
</html>
<?php
$id = 1;
echo " <br> line 44..... <br>";
if("$id")
{
// if id is set then get the file with the id from database
echo " <br> line 50..... <br>";
$a = mysql_connect("localhost","root","");
if (!$a){
die ("<br>ERROR in mysql_connect<br>");
} else
$db = mysql_select_db('test');
echo " <br> line 58..... <br>";
//$id = $_GET;
$query = "SELECT name, type, size, content FROM image 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;
} echo " cant enter line 47...";
?>
************************************************************
thanks :)