bnomei / kirby3-qrcode

Generate QRCodes easily.
https://forum.getkirby.com/t/plugin-qr-code-field-and-page-method/6798
MIT License
12 stars 3 forks source link

Trigger download docs #14

Closed dgsiegel closed 2 years ago

dgsiegel commented 2 years ago

As described in the docs, I added the following to site/templates/default.qr.php

$page->qrcode()->download(
    $page->slug() . '.png'
);

The problem is that the content type will still be set to text/html and hence the download dialog will behave strangely.

image

This can also be confirmed via curl:

HTTP/1.1 200 OK
Host: localhost:8080
Date: Tue, 15 Feb 2022 11:07:28 GMT
Connection: close
X-Powered-By: PHP/8.0.15
Pragma: public
Last-Modified: Tue, 15 Feb 2022 11:07:28 GMT
Content-Disposition: attachment; filename="default.png"
Content-Transfer-Encoding: binary
Connection: close
Cache-Control: no-store
Content-Type:text/html; charset=UTF-8

Changing the template to

$page->qrcode()->download(
    $page->slug() . '.png'
);
exit;

will in fact give you the correct content type:

HTTP/1.1 200 OK
Host: localhost:8080
Date: Tue, 15 Feb 2022 11:05:08 GMT
Connection: close
X-Powered-By: PHP/8.0.15
Pragma: public
Cache-Control: no-cache, no-store, must-revalidate
Last-Modified: Tue, 15 Feb 2022 11:05:08 GMT
Content-Disposition: attachment; filename="default.png"
Content-Transfer-Encoding: binary
Content-type: image/png; charset=UTF-8
Connection: close
dgsiegel commented 2 years ago

Thanks!