php - Deleting files after download -
I am creating an application that allows a user to download a file. After downloading I want to delete the file. The end of my code is like this:
Return response :: Download (public_path). '/ Upload / _tmp /'. Urldecode ($ filename)); Which means that the end of the function ends and I am not able to delete the file. I have tried to call the 'later' filter on the path but then the file is removed quickly.
Any thoughts?
I personally use the following; $ response = response :: create (file_get_contents ($ path_to_file), $ status_code, $ header); The status code is clearly the code that you want to return.
Within $ header parameters, you indexed content-type and content-displacement.
Then you can just unlink $ path_to_file and return a $ response.
There is a very easy way to delete files, which must be used by Jon's answer for the versions of Lernwell and GT; 4.0.
You deleteFileAfterSend return response () - & gt; Download ($ filePath, $ fileName, $ headers) - & gt; ; DeleteFileAfterSend (true);
Comments
Post a Comment