With a post request users can download the image they bought.
Depending on the license the image needs to be resized.
This the controller.
<?php
return function ($kirby) {
$user = $kirby->user();
$download = get('download');
$file = $user->file($download);
$filepath = $file->root();
$name = $file->filename();
if(!$user) go('login');
if($kirby->request()->is('POST') and $download and $file) {
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"" . $name . "\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($filepath));
ob_end_flush();
readfile($filepath);
}
return compact('user');
};
Maybe you can test this solution:
Found the solution:
<?php
return function ($kirby) {
$user = $kirby->user();
if(!$user) go('login');
$download = get('download');
$file = $user->file($download);
$filepath = $file->root();
$name = $file->filename();
if($kirby->request()->is('POST') and $download and $file) {
if ($file->license() == 'lowres') {
kirby()->thumb($file->root(), $file->root(), [
'height' => 1500,
'width' => 1500,
'quality' => 80
]);
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"" . $name . "\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($filepath));
ob_end_flush();
@readfile($filepath);
}
return compact('user');
};