Store images in database

By
Advertisement
HOW TO STORE IMAGES IN DATABASES

<?php
mysql_connect("localhost","root","");
mysql_select_db("test");
$cont = file_get_contents("winter.jpg");
$cont = addslashes($cont);
if(mysql_query("insert into tbl_images values('','$cont')"))
 echo "IMage is added";
else
 echo "not";
?>

TABLE 
sno int auto_increment primary key, image BLOB or LONG BLOB

RETRIEVE IMAGES FROM DATABASE
<?php
header("Content-type:image/jpeg");
mysql_connect("localhost","root","");
mysql_select_db("test");
$data = mysql_query("select * from tbl_images where imgid=3");
$rec = mysql_fetch_row($data);
echo $rec[1];
?>

0 comments:

Post a Comment