Структура проекта
Код: Выделить всё
app (Controller is in here)
public (public site is here)
routes
uploads (file to download is here)
vendor
views
Код: Выделить всё
$app->get('/adm/download/', DownloadController::class . ':download')->setName('adm.download');
Код: Выделить всё
public function download($request, $res, $args) {
$file = "/home/acct/public_html/project/uploads/application/ourfile.jpg";
$response = $res->withHeader('Content-Description', 'File Transfer')
->withHeader('Content-Type', 'application/octet-stream')
->withHeader('Content-Disposition', 'attachment;filename="'.basename($file).'"')
->withHeader('Content-Transfer-Encoding', 'binary')
->withHeader('Expires', '0')
->withHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
->withHeader('Pragma', 'public')
->withHeader('Content-Length', filesize($file));
ob_clean();
flush();
readfile($file);
return $response;
}
Код: Выделить всё
[url={{ url_for(]Download file[/url]
Подробнее здесь: https://stackoverflow.com/questions/784 ... -gibberish
Мобильная версия