Skip to content
This repository

feature #11212 [HttpFoundation] Added a switch to delete file after t…

…he response is send (WybrenKoelmans)

This PR was merged into the 2.6-dev branch.


[HttpFoundation] Added a switch to delete file after the response is send

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | symfony/symfony-docs#3975

I have not done any Unit Tests for this code as I suspect there may already be a way to solve my problem of deleting a file after the request was sent. Is it possible to use `sendContent` and delete the file after that? My attempts were unsuccessful.

If this code is desirable, please assist me in how I would write an unit test for this. Thanks.

- [x] Add unit tests
- [x] Update documentation
- [x] Mention that using `X-Sendfile` will overwrite deleteFileAfterSend


1fff158 [HttpFoundation] Added a switch to delete file after the response is send
latest commit 01346f78e0
Fabien Potencier fabpot authored
File Merge branch '2.4' into 2.5
Resources Merge branch '2.5'
Session Merge branch '2.5'
Tests feature #11212 [HttpFoundation] Added a switch to delete file after t…
.gitignore Added missing files .gitignore
AcceptHeader.php fixed types in phpdocs
AcceptHeaderItem.php fixed types in phpdocs
ApacheRequest.php [HttpFoundation] do not use server variable PATH_INFO because it is a…
BinaryFileResponse.php [HttpFoundation] Added a switch to delete file after the response is … [HttpFoundation] Add ability to change JSON encoding options
Cookie.php fixed types in phpdocs
ExpressionRequestMatcher.php [HttpFoundation] added ExpressionRequestMatcher
FileBag.php [HttpFoundation] fixed typo
HeaderBag.php Merge branch '2.3' into 2.4
IpUtils.php fixed types in phpdocs
JsonResponse.php fixed types in phpdocs
LICENSE update year on licenses
ParameterBag.php [HttpFoundation] Added ParameterBag::getBoolean updated the composer install command to reflect changes in Composer
RedirectResponse.php made {@inheritdoc} annotations consistent across the board
Request.php Merge branch '2.3' into 2.4
RequestMatcher.php [HttpFoundation] Add a way to match a specific scheme in RequestMatcher
RequestMatcherInterface.php fixed types in phpdocs
RequestStack.php unified return null usages
Response.php Merge branch '2.4' into 2.5
ResponseHeaderBag.php [HttpFoundation] Fixed messed up headers
ServerBag.php Merge branch '2.2' into 2.3 (closes #8955)
StreamedResponse.php made types consistent with those defined in Hack
composer.json updated version to 2.6
phpunit.xml.dist removed defaults from PHPUnit configuration

HttpFoundation Component

HttpFoundation defines an object-oriented layer for the HTTP specification.

It provides an abstraction for requests, responses, uploaded files, cookies, sessions, ...

In this example, we get a Request object from the current PHP global variables:

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

$request = Request::createFromGlobals();
echo $request->getPathInfo();

You can also create a Request directly -- that's interesting for unit testing:

$request = Request::create('/?foo=bar', 'GET');
echo $request->getPathInfo();

And here is how to create and send a Response:

$response = new Response('Not Found', 404, array('Content-Type' => 'text/plain'));

The Request and the Response classes have many other methods that implement the HTTP specification.


If you are not using Composer but are using PHP 5.3.x, you must add the following to your autoloader:

// SessionHandlerInterface
if (!interface_exists('SessionHandlerInterface')) {


You can run the unit tests with the following command:

$ cd path/to/Symfony/Component/HttpFoundation/
$ composer.phar install
$ phpunit
Something went wrong with that request. Please try again.