Symfony\Component\HttpFoundation\BinaryFileResponse::deleteFileAfterSend PHP Method

deleteFileAfterSend() public method

If this is set to true, the file will be unlinked after the request is send Note: If the X-Sendfile header is used, the deleteFileAfterSend setting will not be used.
public deleteFileAfterSend ( boolean $shouldDelete ) : BinaryFileResponse
$shouldDelete boolean
return BinaryFileResponse
    public function deleteFileAfterSend($shouldDelete)
    {
        $this->deleteFileAfterSend = $shouldDelete;
        return $this;
    }

Usage Example

 /**
  * Download dataset.
  *
  * @param Request $request
  * @return Response
  */
 public function downloadAction(Request $request)
 {
     $manager = $this->get("accard.outcomes.manager");
     $givenFilename = $request->get("file");
     $filename = $manager->generateExportFilePath($givenFilename);
     if (!$givenFilename || !file_exists($filename) || !is_readable($filename)) {
         throw $this->createNotFoundException("Requested file is invalid, you may only download a file one time before it is deleted.");
     }
     $response = new BinaryFileResponse($filename);
     $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $givenFilename);
     $response->deleteFileAfterSend(true);
     return $response;
 }
All Usage Examples Of Symfony\Component\HttpFoundation\BinaryFileResponse::deleteFileAfterSend