Wrapper for responses in the Symfony HttpFoundation component.
PHP
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
.gitignore
.travis.yml
LICENSE
README.md
composer.json
phpunit.xml

README.md

File Response

Build Status

This package wraps the Response object of the Symfony HttpFoundation component for file output. The concrete classes allow you to avoid the boilerplate involved in setting up a file download response.

Install

Via Composer

{
    "require": {
        "conorsmith/fileresponse": "0.3.*"
    }
}

Available File Types

  • CsvFileResponse (text/csv)
  • GifFileResponse (image/gif)
  • JpegFileResponse (image/jpeg)
  • PdfFileResponse (application/pdf)
  • PngFileResponse (image/png)
  • TextFileResponse (text/plain)
  • ZipFileResponse (application/zip)

Examples

use ConorSmith\FileResponse\TextFileResponse;

$response = new TextFileResponse('example.txt', 'This is the text file\'s contents');
$response->send();

You can use the abstract FileResponse class to create your own custom file responses.

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,
        ));
    }
}