Delete unmanaged file after download? In a custom module I create a file and then use drupal_goto to download it. How can I delete the file after it is downloaded? Placing a file_unmanaged_delete after the drupal_goto doesn't get executed, and hook_file_download happens before the download for permissions checks and such. So I'm not sure how to do this. Do I have to resort to cleaning up files in a folder with cron somehow?
// Generate pdf card.
$file_path = $crm_card-&gt;generatePdfCard();
$filename = basename($file_path);
$headers = [
  'Content-Type' =&gt; 'application/octet-stream',
  'Content-Disposition' =&gt; 'attachment; filename="' . $filename . '"',
  'Content-Length' =&gt; filesize($file_path),
];

$binary_file_response = new BinaryFileResponse($file_path, 200, $headers);
$binary_file_response-&gt;deleteFileAfterSend(TRUE);

return $binary_file_response;