anirudhtomer Posted March 6, 2010 Share Posted March 6, 2010 I insert an image present on localserver to my database using this code: $fp = fopen("xyz","r"); //open an image file in read mode $data = fread($fp,filesize("xyz.jpg")); $data = addslashes($data); fclose($fp); $query = "update imagetable set image = '".$data."'"; mysql_query($query); I checked the image in mysql database using query browser & it gets added successfully there. now I retrieve the image from the following code: $resultset = mysql_query("select image from imagetable"); $row = mysql_fetch_array($resultset); $image = $row['image']; header("Content-type: image/jpeg"); echo $image; now the problem I am facing is that instead of getting an image, I am getting the link of the PHP file in the browser. I AM USING MOZILLA 3.6 1> I even tried using another file which puts the path of this PHP file in its img tag...but that gives empty image 2> tried the thing using echo '<img src ="'.$image.'"/>'; ...but in vain the link of the php file is shown by browser 3> some asked to enter an base64_encoded image in database & retrieve it later ..dosen't work 4> used print $image..same results 5> some asked to not to images in database & instead have them directly at server & store their links in database but I have made the decision to not to use that method. FINALLY THE THING IS AFTER USING EVERYTHING EITHER I GET "link of php file in browser" or "empty image" friends plz help me out...I have :'( searched ocean of forums on this & tried everything they told but I am not able to perform this: plz plz I am tired of this but I want to know the actual reason ... plz be my savior. Quote Link to comment https://forums.phpfreaks.com/topic/194332-not-able-to-retieve-image-from-mysql-and-show-in-webpage/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 6, 2010 Share Posted March 6, 2010 The code you did post is incomplete and cannot produce the results you would need in order to get this to work. For example, the UPDATE and SELECT queries don't contain a WHERE clause so if they actually execute without errors, the result would not be anything you could use. We can only help you with specific problems and with the specific code that you are using. The code you did post in this thread would need to have an existing record in the database in order for the UPDATE query to be the correct method to use. For all we know, the link to the file you got in the browser was something that was already in the database table from previous testing. Quote Link to comment https://forums.phpfreaks.com/topic/194332-not-able-to-retieve-image-from-mysql-and-show-in-webpage/#findComment-1022334 Share on other sites More sharing options...
anirudhtomer Posted March 6, 2010 Author Share Posted March 6, 2010 thanks for the reply Ya I have an existing record in my database & which was initially null...so i updated that later but when I opened mysql to check if image is added using query browser it showed me image... so image is successfully getting added there. the problem is displaying it... do u have any idea how can I display it ... does anybody have the code to "Retrieve an image from database from a database & then display it on a web page"... Quote Link to comment https://forums.phpfreaks.com/topic/194332-not-able-to-retieve-image-from-mysql-and-show-in-webpage/#findComment-1022340 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.