Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
PHP Symfony2: Delete a temp file after response

I have a controller that generates an image and returns the image in the response.

use FOS\RestBundle\Controller\Annotations as Rest;
use Symfony\Component\HttpFoundation\BinaryFileResponse;

...

/**
 * @Rest\Get("/image/{name}")
 */
public function getImage($name) {
    $imageService = $this->get('image.service');
    $tempImage = $imageService->genImage($name);
    return new BinaryFileResponse($tempImage);
}

This works great but temp image never gets deleted.

How do I delete the temp image after the response is sent?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I read though the implementation of BinaryFileResponse. Turns out there is a public method deleteFileAfterSend

I just need

return (new BinaryFileResponse($tempImage))->deleteFileAfterSend(true);
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!