简体   繁体   English

PHP PSR-7响应,获取文件MIME类型

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM