Blob Image

QuestionsBlob Image
Marcel Mizzi asked 2 days ago

I have been trying to display an image in the grid from a Mysql Blob field for hours and can’t seem to be getting anywhere. I am using :

$col[“default”] = “<img src=’data:image/jpeg;base64,” . base64_encode($row[‘file_data’]) . “‘” . “/>”;

where “file_data” contains the image blob data. I have tried lots of things but image does not display in the grid and instead a “broken image” icon appears. I am using the paid version of the grid, btw.

Can anyone help please?

4 Answers
Abu answered 2 days ago

This code seems fine. Please check if the database field is not null.

If you use load_file function of mysql, there seems to be some extra config reqd.
https://www.w3resource.com/mysql/string-functions/mysql-load_file-function.php

Marcel Mizzi answered 2 days ago

Thanks for your reply, however, all I am trying to do is display an image in a grid when the image is stored in a MySQL blob field and I am not using the load_file function. On the same database table, with pure PHP (without Grid4php) I can create an image file and display it withough issues. One difference is that I did not use encode or decode, I simply used file_put_contents to save the content of the blob to a file with a .jpg extension. So, I know the data is good. This is the grid code : $col[\\\”name\\\”] = \\\”file_data\\\”; $col[\\\”width\\\”] = \\\”60\\\”; $col[\\\”editable\\\”] = false; $col[\\\”default\\\”] = \\\'<img src=\\\”data:image/jpeg;base64,\\\’.base64_encode($row[\\\’file_data\\\’]) .\\\’\\\” />\\\’; $cols[] = $col; With file_data being the image data.

Abu Ghufran Staff answered 1 day ago

Try setting base64 conversion in mysql select query.
e.g.
SELECT fid,fname,TO_BASE64(fcontents) as fcontents FROM filecontents

This way, it should not have any issue in ajax call json conversion.
You need to remove base64_encode from php code.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Marcel Mizzi replied 20 hours ago

Thanks. When I tried your suggestion I get the binary image data showing instead of the image.

Abu Ghufran Staff answered 13 hours ago

In your code, you perhpas need. If it does not work, share your code for review.

$col["default"] = "<img width='50' src='data:image/jpeg;base64,{file_data}' />";
_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Marcel Mizzi replied 12 hours ago

Thanks but I tried and all I get is an error box popup with nothing in it.

Here is a link to the code https://gist.github.com/marcelmizzi/2d1328666717bcad9511a4ab413aafc1

Your Answer

20 + 6 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?