BLOB data as src attribute of an image tag? - blob

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.

Related

Displaying jpegPhoto attribute from LDAP in Websphere Portal

I have a requirement wherein I need to display details of users after searching from LDAP using PUMA API.
I'm having troubling displaying the jpegPhoto of the user.
Here's what I'm doing:
First I'm querying the user by using:
PumaLocator.findUsersByAttribute(uid, user);
After that we get a User list Object.
For each user, we fetch all the attributes which is in the form of a Map.
I'm getting the following value for while retrieving the jpegPhoto:
map.get("jpegPhoto") --> [B#7a2f8a54
It seems that the Puma API returns a Binary string. Does anyone know how to display this in the portlet?
Any help would be greatly appreciated. Thank you
I think it more likely this is a byte[] array than a string.
You can probably base64 encode this binary into an encoded string and use it in an HTML image tag.
byte[] photoBytes = (byte[]) map.get("jpegPhoto");
String encodedPhoto = org.apache.commons.codec.binary.Base64.encodeBase64(photoBytes);
Then later, perhaps in a JSP (example assumes JSTL variable in scope named encodedPhoto):
<img src="data:image/jpeg;base64,${encodedPhoto}"/>
A way of doing this is to access the image through the portal service servlet instead of using your own servlet: /wps/um/secure/users/profiles/[oid]/jpegPhoto, in which you replace [oid] with the ObjectID of the user. This ID string can be obtained using IdentificationMgr.getIdentification().serialize(user.getObjectID())
The photo of the current user you can access using: /wps/um/secure/currentuser/profile/jpegPhoto
Portal is giving you data as byte array. It will never give you as URL.
You can write a servlet which will write this byte array to output stream.
Use that servlet URL as src of tag. It will start rendering on browser.
FYI, you can't print byte array to browser and expect it to treat as image.
Image or any other files has to come as a resource not as content.

WebKitGtk2 load from string

In WebKitGtk1 there was a function to load an html page directly from a string.
webkit_web_view_load_string ()
Requests loading of the given content with the specified mime_type ,
encoding and base_uri .
Is there an equivalent in WebKitGtk2? I would like to display an HTML page that is re-generated very often, so saving it as a file and loading this file is no option.
http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html
There are few load methods e.g. webkit_web_view_load_html. Please pick up the one that suits your needs.

New blank page in Zen-Cart

How can I create a new blank page in zen-cart without applying the template.
I want to create a page that will result only a JSON data...
Thanks in advance
Create a php file in your store directory. In that file, if you want to use ZenCart functions you can include them, like so:
<?php
include "includes/application_top.php";
set headers for mime type
set headers for not caching
YOUR CODE
echo $json;
// below is optional if you didn't create/edit session
include "includes/application_bottom.php";

How to add a HTTP header field in Openacs?

I need to add a HTTP header field in the responses of a section of my site, the package instace (my section) is being viewed in a IFRAME and I want to declare a p3p field in order to be able to store cockies in IE 6/7/8 (login doesn't work well), I have an idea of how to do it in PHP and is quite simple:
<?php
header('P3P: CP="CAO PSA OUR"');
?>
but I didn't found how to do it in TCL/openacs, thanks for the help.
Based on Jim Lynch's response when you asked this question elsewhere, you just need to add it to the set of headers being produced for the page.
I'd guess that something like this is probably easiest (assuming you don't want to hard-code the contents of the header; if you did, you could simplify a little):
set cpflags "CAO PSA OUR"
ns_set cput [ns_conn outputheaders] "P3P" "CP=\"$cpflags\""
To understand it, you need to read about ns_conn and ns_set from the AOLserver docs, as well as set from the standard Tcl documentation.

Displaying parsed HTML output using Velocity

i have a velocity template...
It contains the following tag:
#field('itemname')
The "itemname" variable contains this:
<i>Some</i> <b>Example Title</b>
The source of the outputted page has this:
<i>Some</i>
<b>Example Title</b>
So, the user sees the actual HTML tags:
<i>Some</i> <b>Example Title</b>
What I want them to see is:
Some Example Title
Where am I going wrong?
If I see right from your snippets, the problem is not with the velocity template, but with the mime type encoding of the HTTP Response your user is receiving. It should be "text/html", but I suspect it's something else, and so, the browser is showing the tags instead of "rendering" them to what they represent.
Of course, I don't know what your #field() macro does, so the problem might be something else, e.g. that macro might generate a wrapping PRE tag or a Text Area, and this might be the cause you why the those B and I tags are displayed as they are instead of being rendered.