[英]Php PSR-7 response, get file mime-type
I've got a $response
variable, which implements Psr\\Http\\Message\\ResponseInterface
. 我有一个
$response
变量,该变量实现Psr\\Http\\Message\\ResponseInterface
。
It contains info about downloaded file. 它包含有关下载文件的信息。 How can I get mime-type of this file?
如何获得此文件的mime类型?
Since ResponseInterface
extends MessageInterface
, you can use the getHeader($name)
or getHeaderLine($name)
method to retrieve the value of the Content-Type
response header. 由于
ResponseInterface
扩展了MessageInterface
,因此可以使用getHeader($name)
或getHeaderLine($name)
方法检索Content-Type
响应头的值。 For example... 例如...
$mimeType = $response->getHeaderLine('Content-Type');
Note: I used getHeaderLine
as it's unlikely the Content-Type
header will contain more than one value and this will save you treating the return value as a single-item array. 注意:我使用了
getHeaderLine
因为Content-Type
标头不太可能包含多个值,这可以避免将返回值视为单项数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.