-
-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathFile.php
More file actions
30 lines (22 loc) · 712 Bytes
/
File.php
File metadata and controls
30 lines (22 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
declare(strict_types=1);
namespace Tempest\Http\Responses;
use Tempest\Http\ContentType;
use Tempest\Http\IsResponse;
use Tempest\Http\Response;
final class File implements Response
{
use IsResponse;
public function __construct(string $path, ?string $filename = null)
{
$filename ??= pathinfo($path, PATHINFO_BASENAME);
$this
->addHeader('Content-Disposition', "inline; filename=\"{$filename}\"")
->setContentType(ContentType::fromPath($path))
->removeHeader('Transfer-Encoding');
if ($filesize = filesize($path)) {
$this->addHeader('Content-Length', "{$filesize}");
}
$this->body = $path;
}
}