I use this to send the file to the user
header('Content-type: application/zip'); header('Content-Length: ' . filesize($file)); header('Content-Disposition: attachment; filename="file.zip"'); readfile($file);
I want to delete this file after user downloads, how can I do this?
EDIT: my script is like this, when the user presses the download button, my script will create a temporary zip file and the user will upload it, after which the temporary zip file will be deleted.
EDIT2: OK. The best way seems to be running a cron job that will clean up temporary files once per hour.
EDIT3: I tested my script using unlink , it works if the user does not cancel the download. If the user cancels the download, the zip file will remain on the server. So thatβs enough. :)
EDIT4: WOW! connection_aborted() did the trick!
ignore_user_abort(true); if (connection_aborted()) { unlink($f); }
This file will be deleted even if the user cancels the download.
php
Utku Dalmaz Apr 14 '10 at 23:08 2010-04-14 23:08
source share