Jump to content

Recommended Posts

//DB Connection

$sql ="select img_val from image where id=152";
$result = mysql_query($sql);

while ($row = mysql_fetch_assoc($result)) {
    $Image=$row['img_val'];
#       print "Image is $Image";
}

header( "Content-type: image/jpeg");
echo "<img src=\"$Image\"; alt=\"Image from DB\" />";

When I view the file in browser, some characters are printed and not the image.

Please tell me how to view the exact image in the browser.

Link to comment
https://forums.phpfreaks.com/topic/204068-view-image-in-browser/
Share on other sites

The <img src="..." attribute value MUST BE a URL to an image, NOT binary image data.

 

The URL that you put into the src="..." attribute must cause the correct Content-type: header to be output, followed by the binary image data.

 

Since you are outputting the binary image data using a .php script, you would put a .php file in as the URL. You will also typically put a GET parameter on the end of the URL that indicates which image you want (so that you can use the same .php file to output any available image.)

 

The <img tag that you produce for your web page would look something like -

 

<img src="myimage.php?id=152" alt="">

 

The myimage.php file (or whatever name you choose) will need to get the id (using $_GET['id']), validate it, and put that into the query in order to retrieve the correct binary image data.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.