pour prod
This commit is contained in:
27
app/Core/PdfResponse.php
Normal file
27
app/Core/PdfResponse.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user