I am doing PHP for the first time and research about this but not joy. Basically, i am trying to get the images from my PHPMyAdmin database and upload it to a webpage that i have created. All the heading and texts are being displayed as intended apart from the image.
Code in which i am getting the images from database
<?php
include 'config.php';
include 'opendb.php';
$getdestinationdetails = mysql_query("SELECT *
FROM tbldestinations
WHERE destinationid = $_GET[destinationid]");
while($row = mysql_fetch_array($getdestinationdetails))
{
echo "<h1>Visit " . $row['destinationname'] . "</h1>".
"<imgsrc = 'images" . $row['destinationimage'] . "' />" .
"<br />
<br />" .
$row['destionationdesc'] .
"<br />
<br />
Our holidays include:
<ul>
<li>Luxury coach travel from Shipley Town Centre</li>
<li>Bed and Breakfast at a top hotel</li>
<li>Free tea and coffee on board your coach</li>
<li>The services of an experienced courier</li>
<li>Free complimentary glass of champagne upon arrival at your hotel</li>
</ul>
<center><h2>Don't delay, book today!</h2></center>";
}
include 'closedb.php';
?>
I tried all the experiments but all in vain. any tips or suggestions would be really appreciated. Thanks in advance
header('Content-Type: image/jpeg')
(or whatever the type of image that you will display is. Then, you will output the content. This option might not be as preferred, as it takes an extra call to the database (http://stackoverflow.com/questions/5525830/displaying-an-image-stored-in-a-mysql-blob)Either option, you will need to still have an <img />
tag on your main page. Option 1 requires a src
attribute pointing to the script, including whatever identifiers needed to look up the image in the database (but being very careful about XSS). Option 2 outputs it directly into the image tag, so that is preferable in some respects as well
Your above code should work fairly fine, except with this modification:
echo "<h1>Visit " . $row['destinationname'] . "</h1>".
"<img src=\"images/" . $row['destinationimage'] . "\" />" .
...
What I would do, which would be the easiest is this: in your php file, output your image (assuming it is a jpg), like this:
...
echo '<img src="data:image/jpeg;base64,' . base64_encode($row['destinationimage']) . '" />';
...
The above will actually put the image into the image tag itself, instead of downloading across the internet. I think the hangup here is the fact that you are seeing the image in PHPmyAdmin. When you see the image there, there really is no way to get it out of PHPmyAdmin. I haven't tried it myself, but I would assume that they are doing something similar to what I show you above - just displaying the image in the HTML tag.