改名
This commit is contained in:
@@ -119,10 +119,14 @@ class Response extends HttpService implements ResponseInterface
|
||||
* @param bool $isChunk
|
||||
* @param int $limit
|
||||
* @return $this|Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendFile(string $path, bool $isChunk = false, int $limit = 10240): static
|
||||
{
|
||||
$this->format = self::FILE;
|
||||
if (!file_exists($path)) {
|
||||
throw new Exception('File `' . $path . '` not exists.');
|
||||
}
|
||||
$this->endData = ['path' => $path, 'isChunk' => $isChunk, 'limit' => $limit];
|
||||
return $this;
|
||||
}
|
||||
@@ -262,7 +266,7 @@ class Response extends HttpService implements ResponseInterface
|
||||
/** @var SResponse $response */
|
||||
$response = Context::getContext('response');
|
||||
if (!empty($response)) {
|
||||
return $response->redirect($url,302);
|
||||
return $response->redirect($url, 302);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ namespace Server\Constrict;
|
||||
use Exception;
|
||||
use HttpServer\Http\Formatter\FileFormatter;
|
||||
use Server\ResponseInterface;
|
||||
use Snowflake\Abstracts\Config;
|
||||
use Snowflake\Exception\ConfigException;
|
||||
|
||||
|
||||
/**
|
||||
@@ -38,6 +36,18 @@ class ResponseEmitter
|
||||
*/
|
||||
private function download(array $content, \Swoole\Http\Response $response)
|
||||
{
|
||||
$explode = explode('/', $content['path']);
|
||||
|
||||
$response->header('Pragma', 'public');
|
||||
$response->header('Expires', '0');
|
||||
$response->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
|
||||
// $response->header('Content-Type', 'application/force-download');
|
||||
$response->header('Content-Type', 'application/octet-stream');
|
||||
// $response->header('Content-Type', 'application/vnd.ms-excel');
|
||||
// $response->header('Content-Type', 'application/download');
|
||||
$response->header('Content-Disposition', 'attachment;filename=' . end($explode));
|
||||
$response->header('Content-Transfer-Encoding', 'binary');
|
||||
|
||||
if ($content['isChunk'] === false) {
|
||||
$response->sendfile($content['path']);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user