VIEW (HTML)
<tbody>
<?php foreach ($order_data as $key => $value): ?>
<tr>
<td> <?php echo $value['id'] ?> </td>
<td> <img src="<?php echo base_url('z_ex/v_1/render/generateQRcode/'.$value['id']) ?>" alt="..."> </td>
</tr>
<?php endforeach; ?>
</tbody>
Controller (SCRIPT)
<?php defined('BASEPATH') or exit('No direct script access
allowed');
ini_set('display_errors', 1);
error_reporting(E_ALL);
require "vendor/autoload.php";
use Endroid\QrCode\QrCode;
class Render extends Admin_Controller
{
public function __construct()
{
parent::__construct();
$this->not_logged_in();
}
public function index(){
if (!in_array('viewOrder', $this->permission)) {
redirect('z_ex/v_1/dashboard', 'refresh');
}
$data = $this->model_orders->getOrdersTrackingNum();
$this->data['data'] = $data;
$this->load->view('render', $this->data);
}
public function generateQRcode($bill_no = 123456) {
$qr = new QrCode("HEy there");
header('Content-Type: '.$qr->getContentType());
echo $qr->writeString();
}
}
I am using Endroid QrCode package for generating QR code and it shows this way (as on the picture), NO ERROR, NO WARNING, Just a black background with a small white square., I changed the output to be written on a file and save it, IT WORKS. But i do not want to save it, I just want it to be displayed when I call it dynamically and that is it. The Header is set to image/png as you can see from the right side of the image.
CodePudding user response:
Finally fixed the problem by adding data:image/png;base64
to the src
of img tag
in the HTML and it worked.
Thanks to everybody.