I'm trying to simply store and then show image in database.
database name "dota2"
table "images"
id(int11)
pics(blob)
ext(varchar4)
gender(varchar7)
storing code, it works, well atleast it adds data to the database i dont know if the data is proper.
PHP Code:
<?php
$con = mysql_connect("localhost","root","aa");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
echo "Success! You have connected ";
$handle = fopen("ch.jpg", "rb");
$img = fread($handle, filesize('ch.jpg'));
fclose($handle);
if (!$img)
{echo"not working";}
$img = base64_encode($img);
mysql_connect("localhost","root","aa") or die(mysql_error());
mysql_select_db("dota2") or die(mysql_error());
$sql = "INSERT INTO images(id, pics, ext, gender) values (null,'$img','jpg','china')";
mysql_query($sql) or die('Bad Query at 12');
echo "Success! You have inserted your picture!";
?>
but now i cant get it from my database(cant show it), getting error "The image "http://localhost/showing/" cannot be displayed because it contains errors"
get image code
PHP Code:
<?php
$link = mysql_connect("localhost","root","aa");
mysql_select_db("dota2");
$sql = "SELECT pics FROM images WHERE id=1";
$result = mysql_query("$sql");
header("Content-type: image/jpeg");
echo mysql_result($result, 0);
mysql_close($link);
?>
any help ?
edit: the id is definitely 1
Bookmarks