28 lines
764 B
PHP
28 lines
764 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Core;
|
|
|
|
final class PdfResponse
|
|
{
|
|
public static function inline(string $content, string $filename): void
|
|
{
|
|
$safeFilename = preg_replace('/[^A-Za-z0-9._-]+/', '_', $filename) ?: 'planning.pdf';
|
|
if (!str_ends_with(strtolower($safeFilename), '.pdf')) {
|
|
$safeFilename .= '.pdf';
|
|
}
|
|
|
|
if (!headers_sent()) {
|
|
header('Content-Type: application/pdf');
|
|
header('Content-Disposition: inline; filename="' . $safeFilename . '"');
|
|
header('Content-Length: ' . strlen($content));
|
|
header('Cache-Control: private, max-age=0, must-revalidate');
|
|
header('Pragma: public');
|
|
}
|
|
|
|
echo $content;
|
|
exit;
|
|
}
|
|
}
|