Developed with love by KnpLabs Hire us for your project!
138

IgorwFileServeBundle

by igorw

Symfony2 Bundle for serving protected files.

FileServeBundle

About

The FileServeBundle allows you to serve files that are not publicly available,
such as private attachments.

Installation

Add the bundle to your composer.json:

{
    "require": {
        "igorw/file-serve-bundle": "~1.0"
    }
}

Add the FileServeBundle to your application's kernel:

public function registerBundles()
{
    $bundles = array(
        // ...
        new Igorw\FileServeBundle\IgorwFileServeBundle(),
        // ...
    );
    // ...
}

Usage

Use the igorw_file_serve.response_factory service to create a FileServe
response. The path is relative to the app directory by default.

$response = $this->get('igorw_file_serve.response_factory')->create('../VERSION', 'text/plain');

You can also pass a set of options as the third parameter of the create
method.

$options = array(
    'serve_filename' => 'VERSION.txt',
    'absolute_path' => true,
    'inline' => false,
);

$response = $this->get('igorw_file_serve.response_factory')
    ->create('../VERSION', 'text/plain', $options);
  • serve_filename: Filename the browser downloads the file as.
  • absolute_path: If enabled, the bundle will ignore the base_dir option and use the provided filename as an absolute path.

You can configure the factory used, for example to use a nginx XSendfile
response factory:

igorw_file_serve:
    factory: sendfile     # The default value is "php"

You can also configure the base directory:

igorw_file_serve:
    base_dir: /files/dir     # The default value is "%kernel.root_dir%"

By default, this bundle does a file_exists check when creating a response
object. Recent nginx versions require relative paths, in which case the paths
inside of PHP are not actual physical paths. Use the skip_file_exists
setting to disable the check.

igorw_file_serve:
    skip_file_exists: true  # The default value is false

Supported factories

  • php
  • sendfile (nginx)
  • xsendfile (apache)

Features

Todo

  • Tests
  • HTTP caching
  • HTTP range requests
  • Lighttpd XSendfile
  • Handle PhpResponse getContent(), setContent()
Copyright (c) 2011 Igor Wiedler

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
igorw_file_serve:
factory: php
base_dir: %kernel.root_dir%
skip_file_exists: false
  • Merge pull request #14 from h4cc/patch-1
    By igorw, 3 years ago
  • Added PHP 5.5 to travis.
    By h4cc, 3 years ago
  • Merge pull request #13 from mhor/patch-2
    By igorw, 3 years ago
  • Syntax highlighting on README.md
    By mhor, 3 years ago
  • Prepare v1.0.3 release
    By igorw, 3 years ago
  • fix missing container configuration
    By igorw, 3 years ago
  • Add bundle config option to disable file_exists check (requested by daum on IRC)
    By igorw, 3 years ago
  • semantic versioning in README
    By igorw, 3 years ago
  • Replace readfile with stream_copy_to_stream, closes #9
    By igorw, 4 years ago
  • Use pre-installed travis composer bin
    By igorw, 4 years ago
  • Add tests for all response factories
    By igorw, 4 years ago
  • Add credits for inmarelibero and kbond
    By igorw, 4 years ago
  • Add bugfix to CHANGELOG
    By igorw, 4 years ago
  • Change test annotations to single-line format
    By igorw, 4 years ago
  • Add trailing newline back to internet.txt fixture
    By igorw, 4 years ago
  • Remove .idea from .gitignore
    By igorw, 4 years ago
  • Merge remote-tracking branch 'kbond/patch-1'
    By igorw, 4 years ago
  • added some sanity tests and travis-ci config
    By kbond, 4 years ago
  • fixed typo
    By kbond, 4 years ago
  • Refactor absolute path patch, rename option to absolute_path
    By igorw, 4 years ago
  • Merge remote-tracking branch 'inmarelibero/master'
    By igorw, 4 years ago
  • tweaked date
    By Emanuele Gaspari, 4 years ago
  • refactored code to respect original pattern
    By Emanuele Gaspari, 4 years ago
  • removed unnecessary parameter binding
    By Emanuele Gaspari, 4 years ago
  • Add hard dependency on symfony/http-foundation
    By igorw, 4 years ago
  • Prepare 1.0.0 release
    By igorw, 4 years ago
  • Switch README instructions to suggest composer installation
    By igorw, 4 years ago
  • Add branch alias so that dev-master becomes 1.0.*@dev
    By igorw, 4 years ago
  • Remove hard dependency on symfony/framework-bundle
    By igorw, 4 years ago
  • added support for absolute filenames to serve
    By inmarelibero, 4 years ago