This commit is contained in:
2021-08-10 17:08:33 +08:00
parent 9557989011
commit 15cbf0c236
+12 -2
View File
@@ -5,6 +5,7 @@ namespace Server\Constrict;
use Exception; use Exception;
use HttpServer\Http\Formatter\FileFormatter; use HttpServer\Http\Formatter\FileFormatter;
use Server\ResponseInterface; use Server\ResponseInterface;
use validator\EnumValidator;
/** /**
@@ -47,12 +48,21 @@ class ResponseEmitter
// $response->header('Content-Type', 'application/download'); // $response->header('Content-Type', 'application/download');
$response->header('Content-Disposition', 'attachment;filename=' . end($explode)); $response->header('Content-Disposition', 'attachment;filename=' . end($explode));
$response->header('Content-Transfer-Encoding', 'binary'); $response->header('Content-Transfer-Encoding', 'binary');
$response->setStatusCode(200);
if ($content['isChunk'] === false) { if ($content['isChunk'] === false) {
$response->sendfile($content['path']); $response->sendfile($content['path']);
return; } else {
$this->chunk($content, $response);
}
} }
/**
* @param $content
* @param $response
*/
private function chunk($content, $response): void
{
$resource = fopen($content['path'], 'r'); $resource = fopen($content['path'], 'r');
$state = fstat($resource); $state = fstat($resource);