0

I am trying to display an image, but my webpage displays encoding stuff instead. Below is my code:

<?php ob_start();?>

// html markups goes here

<?php include 'login.php';
if(isset($_GET['productid'])){
    $productid = $_GET['productid'];

    $sql = "select tyre_image from tyres where product_id = '$productid'";
    $result = mysql_query($sql) or die(mysql_error());
    header("Content-type :image/jpg");
    echo mysql_result($result,0);

}

ob_end_flush();

?>

I am using $_GET associative array($_GET['variable']) to get the product ID via a link on another page.

How would I fix this?

1
  • why do you save the images into the DB instead of the path? Commented May 9, 2013 at 14:48

1 Answer 1

3

I had no idea the Content-type header was this picky, but change the spacing around the colon (and also image/jpg should be image/jpeg):

header("Content-type: image/jpeg");

Per the answer below, I agree - this fix assumes that this script is just used for displaying an image in your HTML, ala <img src="path/to/your/image.php?productid=123" />.

Further light reading on the image/jpeg MIME type spec here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.