deleting a file after user download it
<p>i am using this for sending file to user</p>

<pre><code>header('Content-type:  application/zip');
header('Content-Length: ' . filesize($file));
header("Content-Disposition: attachment; filename="file.zip");
readfile($file);
</code></pre>

<p>i want to delete this file after user download it, how can i do this ?</p>

<p>thx</p>

<p>EDIT: my scenario is like that, when user hits download button, my script will create a temp. zip file and user download it then that temp zip file will be delete</p>

<p>EDIT2: OK best way seems running a cron job that will be cleaning temp files once an hour.</p>

<p>EDIT3: I tested my script with <code>unlink</code> , it works unless user cancel the download. if user cancel the download, zip file stays on the server. so that is enough for now :)</p>

<p>EDIT4: WOW! <code>connection_aborted()</code> made the trick !</p>

<pre><code>ignore_user_abort(true);
if (connection_aborted()) {
unlink($f);
}
</code></pre>

<p>this one will delete the file even if user cancel the download. </p>
