After using the PHP QrCode lib I discovered that for some reason when using a dynamic page with scripts and dialog boxes (JQuery) that when trying to output a QR code in a .png format I get weird symbols instead of the actual generated .png file.
Heres what I have tried:
Created a seperate file with just:
//include only that one, rest required files will be included from it
�PNG IHDRWWKK/PLTE���U��~�IDAT8��ѱ � P# �c��n :V�L�@�k
The problem is here:
<html> <?php QRcode::png('barrda554'); ?> </html>
To understand what this is doing, imagine that you open a regular PNG file in a text editor, and just copy/paste the contents directly into your HTML file. It's not going to show an image - it'll just be garbage, like you're seeing.
To include an image in an HTML file, you need to use the
<img> tag, and point to the URL of the image. In this case, the URL of the image would be a PHP script that outputs nothing except the PNG contents - like this:
And then in qrcode.php, generate the image:
<?php include "phpqrcode/qrlib.php"; QRcode::png('barrda554'); ?>
If you need some information from the HTML page in order to generate the image, you can include it as query parameters in the URL, like this:
And then get those values in your PHP like this:
<?php include "phpqrcode/qrlib.php"; $product = $_GET['product']; $format = $_GET['format'] // ... // whatever you need to do to generate the proper code // ... QRcode::png('barrda554'); ?>
And finally - there are ways to include the image data directly into the HTML page, but it's not supported by all browsers, and is not recommended because it makes the page size much larger and prevents the browser from being able to cache the image separately.