mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 19:58:22 +08:00
Optimized comment
This commit is contained in:
parent
333c99c18b
commit
d43cabb7ec
@ -46,7 +46,10 @@ interface ResponseInterface
|
||||
public function redirect(string $toUrl, int $status = 302, string $schema = 'http'): PsrResponseInterface;
|
||||
|
||||
/**
|
||||
* Create a new file download response.
|
||||
* Create a file download response.
|
||||
*
|
||||
* @param string $file The file path which want to send to client.
|
||||
* @param string $name The alias name of the file that client receive.
|
||||
*/
|
||||
public function download(string $file, string $name = ''): PsrResponseInterface;
|
||||
}
|
||||
|
@ -115,6 +115,12 @@ class Response implements PsrResponseInterface, ResponseInterface
|
||||
return $this->getResponse()->withStatus($status)->withAddedHeader('Location', $toUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a file download response.
|
||||
*
|
||||
* @param string $file The file path which want to send to client.
|
||||
* @param string $name The alias name of the file that client receive.
|
||||
*/
|
||||
public function download(string $file, string $name = ''): PsrResponseInterface
|
||||
{
|
||||
$file = new \SplFileInfo($file);
|
||||
@ -140,6 +146,7 @@ class Response implements PsrResponseInterface, ResponseInterface
|
||||
|
||||
return $this->withHeader('content-description', 'File Transfer')
|
||||
->withHeader('content-type', value(function () use ($file) {
|
||||
$mineType = null;
|
||||
if (ApplicationContext::hasContainer()) {
|
||||
$guesser = ApplicationContext::getContainer()->get(MimeTypeExtensionGuesser::class);
|
||||
$mineType = $guesser->guessMimeType($file->getExtension());
|
||||
|
Loading…
Reference in New Issue
Block a user