Blob Image

QuestionsBlob Image
Marcel Mizzi asked 13 hours 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?

3 Answers
Abu answered 10 hours 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 6 hours 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 18 mins 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
 
Your Answer

2 + 5 =

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?