开发者

retrieving images from MySQL class and posting them in-page

I have a bunch of book covers store开发者_StackOverflow社区d in a column in my book_cache table. I'd like to use the code below to retrieve these cover by doing

<img src="<?php $bcontroller->getCover($isbn_10); ?>">

However this doesn't work at all....I know how to display each image alone on its own page. I've also been able to create a php script that fetches them from database by calling

<img src="script.php?id=$isbn_10">

however I would prefer to post the images directly from the $bcontroller object class.

Thanks in advance for the help, everyone on here is always very knowledgable.

public function getCover($isbn_10){
    $stmt = $this->db_conn->prepare("SELECT cover, mime_type, file_size FROM book_cache WHERE isbn10=?");
    $stmt->bind_param('s', $isbn_10);
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($cover, $mime, $size);
    while ($stmt->fetch()) {
    }
    $stmt->close();
    header("Content-Type: ".$mime);
    echo $cover;
}


Just ask yourself a question: can you make it with plain HTML? By placing all images right into HTML code?

Although there is some unusual way to put images right on the page, it's not recommended.
So, you have to stick with calling your image script.

That's why it's recommended not to store images in the database for use on a web site. I hope now you can see it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜