我正在使用WordPress插件开具发票.这个插件有可定制的模板,你可以编辑.在该模板中,我获取变量,然后将其包含在指向所需图像的路径中,然后将该图像添加到模板中.
<?php
$order_id_image = $this->order_number();
$order_id_image_num = strval($order_id_image);
echo '<div>'.$order_id_image.'</div>';
$file_path_qr_image_base = 'wp-content/uploads/qr_upn_private/'.$order_id_image_num.".png";
$base_image = file_get_contents($file_path_qr_image_base);
echo '<div>'.$file_path_qr_image_base.'</div>';
echo '<img src="data:image/gif;base64,' . $base_image . '" />';
$order_id_image = $this->order_number();
$file_path_qr_image_base = 'wp-content/uploads/qr_upn_private/'.$this->order_number().".png";
?>
在测试时,输出如下:function output
如果我将路径写入静态映像,它将工作$file_path_qr_image_base = 'wp-content/uploads/qr_upn_private/4213.png';
提前感谢您:)
Solution
在我的特定情况下,$this->order_number();
返回空值.
所有问题都记录在文件/wp-content/debug.log中
这指导我使用以下方法来纠正解决方案:
$id = $order->get_id(); //to retrive id
$data = file_get_contents("/home/{your_site}/public_html/wp-content/uploads/folder/".$id.".png");
echo '<img src="data:image/png;base64,' . $data . '" style="height:250px">';