conorsmith / fileresponse
此包已被放弃,不再维护。未建议替代包。
用于 Symfony HttpFoundation 组件中响应的包装器。
v0.3.1
2014-09-06 13:13 UTC
Requires
- symfony/http-foundation: 2.6.*@dev
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2021-09-06 07:57:18 UTC
README
此包包装了 Symfony HttpFoundation 组件 中的 Response 对象,用于文件输出。具体类允许您避免设置文件下载响应时涉及的样板代码。
安装
通过 Composer
{
"require": {
"conorsmith/fileresponse": "0.3.*"
}
}
支持的文件类型
- CsvFileResponse (text/csv)
- GifFileResponse (image/gif)
- JpegFileResponse (image/jpeg)
- PdfFileResponse (application/pdf)
- PngFileResponse (image/png)
- TextFileResponse (text/plain)
- ZipFileResponse (application/zip)
示例
use ConorSmith\FileResponse\TextFileResponse;
$response = new TextFileResponse('example.txt', 'This is the text file\'s contents');
$response->send();
您可以使用抽象的 FileResponse 类来创建自己的自定义文件响应。
use ConorSmith\FileResponse\FileResponse;
class NsfwJpegFileResponse extends FileResponse
{
public function __construct($filename, $content)
{
parent::__construct($filename, $content, array(
'Content-Type' => 'image/jpeg',
'X-Content-NSFW' => true,
));
}
}