UploadedFileResponse.php 7.00 KiB
<?php
/*
 * Copyright (C) 2015 IRSTEA
 * All rights reserved.
 */
namespace Irstea\FileUploadBundle\Http;
use DateTime;
use Irstea\FileUploadBundle\Model\UploadedFileInterface;
use LogicException;
use SplFileInfo;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
 * Description of UploadedFileResponse
 * Très, très, fortement inspiré de Symfony\Component\HttpFoundation\UploadedFileResponse.
 * @author Guillaume Perréal <guillaume.perreal@irstea.fr>
class UploadedFileResponse extends Response
    /**
     * @var UploadedFileInterface
    protected $file;
    /**
     * @var int
    protected $offset = 0;
    /**
     * @var int
    protected $maxlen;
    /**
     * Constructor.
     * @param UploadedFileInterface $file               The file to stream
     * @param int                   $status             The response status code
     * @param array                 $headers            An array of response headers
     * @param bool                  $public             Files are public by default
     * @param null|string           $contentDisposition The type of Content-Disposition to set automatically with the filename
    public function __construct(UploadedFileInterface $file = null, $status = 200, $headers = array(), $public = true, $contentDisposition = null)
        parent::__construct(null, $status, $headers);
        if ($file) {
            $this->setFile($file, $contentDisposition);
        if ($public) {
            $this->setPublic();
    /**
     * @param UploadedFileInterface  $file               The file to stream
     * @param int                   $status             The response status code
     * @param array                 $headers            An array of response headers
     * @param bool                  $public             Files are public by default