I faced the same situation. So I just want to share the following information if it helps people in need.
Actually
force_download ("file name", $ filepath);
Nothing that you wrote after this piece of code is executed because the force_download method has a header and an exit call .
So, if you want to delete the downloaded file, you can delete it before calling the force_download method .
, . force_download . , .
$file_content = file_get_contents($file_path);
if(file_exists($file_path)){
unlink($file_path);
}
force_download($filename, $file_content);