Columns.render calling a PHP function?
Columns.render calling a PHP function?
What's the best way to go about this. I've searched the forums and web and have come up short.
I have raw data being parsed as a CSV file and it comes in just fine. I have images in a seperate folder. I want to use columns.render to write the <img> tag based on the row data.
I want to include a php function in the img src to convert the image to base64 formatting.
Here is my code
$('#datasource').DataTable( {
data: results.data,
columns: [
{ title: "Style", defaultContent: "" },
{ title: "Color", defaultContent: "" },
{ title: "Style Desc", defaultContent: "" },
{ title: "Color Desc", defaultContent: "" },
{ title: "XS", type: "num", defaultContent: "" },
{ title: "S", type: "num", defaultContent: "" },
{ title: "M", type: "num", efaultContent: "" },
{ title: "L", type: "num", defaultContent: "" },
{ title: "X", type: "num", defaultContent: "" },
{ title: "XX", type: "num", defaultContent: "" },
{ title: "XXXL", type: "num", defaultContent: "" },
{ title: "4XL", type: "num", defaultContent: "" },
{ title: "5XL", type: "num", defaultContent: "" },
{ title: "Grand Total", type: "num", defaultContent: "" },
{ title: "ImageSrc", orderable: false, data: null, render:
function ( data, type, row) {
return '<img src="<?php echo base64_encode_image ('images/' + row[0] + '_NEU_BLANK_' + row[1] + '_MF.low.res.jpeg','jpeg'); ?>"/>'
}
Here is the PHP
<?php
function base64_encode_image ($filename=string,$filetype=string) {
if ($filename) {
$imgbinary = fread(fopen($filename, "r"), filesize($filename));
return 'data:image/' . $filetype . ';base64,' . base64_encode($imgbinary);
}
}
Answers
You can't do that I'm afraid. There are three options I can think of:
<img>
tag that will load the image from a PHP script (i.e. one request for each image).Allan