lundi 20 avril 2015

Trying to echo an Image from BLOB

I have a page where a user enters an ID for a book record and it is supposed to pull the corresponding image (only the image) that was entered with a books details from the database which is stored as a BLOB. - Yes, its better to store the image file path - I know this, but that's not what i'm trying to achieve here.

Currently when I press the submit button to find an ID specific by user it displays a page with an image symbol, but no image.

Here is my code.

require_once __DIR__.'/config.php';
session_start();
$dbh = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_USERNAME, DB_USERNAME, DB_PASSWORD);

$book = $_POST["book_id"];
$stmt = $dbh->prepare("select image from books2 where b_id = $book ");
$stmt->execute();


if ($stmt) {
    if ($row = $dbh->prepare($stmt)) {
       $img = $row["image"];
    }
}

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

echo "$img";

How do I get the image to display, I have read other questions but haven't been able to figure it out?

Aucun commentaire:

Enregistrer un commentaire