I tried to insert an image into database and retrieve it from the database. I have successfully inserted the image but it’s not displaying me the retrieved image. However I can see that the binary data of the image is being retrieved but it isn’t displaying in a image format. Here is the code:
upload.php :
<?php if(isset($_POST['submit'])) { $db=mysql_connect("localhost","root",""); mysql_select_db("picture",$db); $image=$_FILES["img"]["tmp_name"]; $name=addslashes($_FILES["img"]["name"]); $contents=addslashes(file_get_contents($_FILES["img"]["tmp_name"])); //echo $name." ".$contents; $res=mysql_query("insert into pics values('{}','{$name}','{$contents}')"); if($res==true) { echo "Done"; $lastid=mysql_insert_id(); echo ""; } else echo "Try again"; } ?>
getimg.php :
<?php $db=mysql_connect("localhost","root",""); mysql_select_db("picture",$db); $id=addslashes($_REQUEST['id']); $res=mysql_query("select * from pics where id=$id"); $res=mysql_fetch_assoc($ res); $res=$res['image']; header("Content-type:image/jpeg"); echo $res; ?>Please help.