mirror of
https://github.com/getformwork/formwork.git
synced 2025-02-22 16:56:50 +01:00
Add FileResponse
class
This commit is contained in:
parent
99759734d3
commit
eeac856567
31
formwork/src/Response/FileResponse.php
Normal file
31
formwork/src/Response/FileResponse.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Formwork\Response;
|
||||
|
||||
use Formwork\Utils\FileSystem;
|
||||
use Formwork\Utils\HTTPResponse;
|
||||
|
||||
class FileResponse extends Response
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function __construct(string $path, bool $download = false, int $status = 200, array $headers = [])
|
||||
{
|
||||
$headers += [
|
||||
'Content-Type' => FileSystem::mimeType($path),
|
||||
'Content-Disposition' => $download ? 'attachment; filename="' . basename($path) . '"' : 'inline',
|
||||
'Content-Length' => FileSystem::fileSize($path)
|
||||
];
|
||||
parent::__construct(FileSystem::read($path), $status, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function send(): void
|
||||
{
|
||||
HTTPResponse::cleanOutputBuffers();
|
||||
parent::send();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user