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?
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
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.
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.