开发者

BLOB data as src attribute of an image tag?

I've inherited a site that uses a 开发者_运维技巧less then ideal way to handle images, they have been stored in the DB as BLOBs. The image tags consist of

<img src='image.php?id=22' />

but no images are displaying. When I visit the image.php?id=22 page, the BLOB data is just dumped out on to the screen (all funny characters) and no image is shown. I'm not sure if this has to do with the content type of data that's being sent to the browser? I've been told "this used to work fine until a few weeks ago".

My question is, is it even possible to display BLOB data as the src attribute of an image tag?

EDIT: by request, here are the contents of image.php. Hope this is of some use.

<?
error_reporting(0);
include("../inc/connect.inc");
include("../inc/common.inc");
include("item.class");
$item = new Item($id);
echo $item->Picture;
?>

EDIT2: If i add the content-type line, the page just prints out the path to the image: http://www.site.com/dir/image.php?id=49. Tried with several content types, no difference. Strange!


You should have, in the database, a content-type field as well as the BLOB data, unless the BLOB data is one fixed type (e.g., image/png) where you can hardcode it in your image.php script. You'll need to include a new header with the Content-type: set.

header('Content-type: image/png');

But you'll have to find out what the image type is - trial and error will do I guess, it's gotta be one of image/jpeg, image/png or image/gif surely?


Well, if you linked directly to the image the exact same data would be sent back, there's no distinction between a 'BLOB' and just data read by the webserver and sent to the browser.

So, you're on the right track with the content-type idea... What does firebug say the content-type is? You might want to post the code for image.php.

edit:

So there we go... Just modify your script to look like:

<?
header( 'Content-Type: image/png' );
error_reporting(0);
include("../inc/connect.inc");
include("../inc/common.inc");
include("item.class");
$item = new Item($id);
echo $item->Picture;
?>

Replacing image/png with whatever format your images are.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜