Forum Moderators: coopster

Message Too Old, No Replies

Automatic deletion of .zip file after download

how to send user a file then delete?

         

cochranrg

3:18 pm on May 16, 2006 (gmt 0)

10+ Year Member



I have written a PHP page that ZIPs some bulletin files together for download by the user. Since I have multiple users that may be doing this at once I am creating .ZIP files with random names.

How do I delete these files after download? Or, how do I force a download to the user so that I can automatically delete the files? I know that some sites I have used, when you download a file it automatically opens a directory window on my computer and the file is in it.

Anyway, I am at a loss. These files are large and I don't need them filling up the server.

Any and all help GREATLY appreciated!

RC

dreamcatcher

3:20 pm on May 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi cochranrg,

I believe the unlink [uk.php.net] function is what you are looking for.


if (file_exists($file))
{
unlink ($file);
}

dc

cochranrg

3:29 pm on May 16, 2006 (gmt 0)

10+ Year Member



Thanks DC, but not really what I need. Don't think I can do what I want.

What I really need is a way to know that the file has been downloaded. But I now believe this is impossible.

I'm thinking of writing a background script that deletes these files every so often, but could catch someone during the download and mess it up. Quite the pickle!

RC

coopster

3:53 pm on May 16, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



dc is saying to zip and write the file out to the browser with the correct headers right away. At the end of the process you would then delete (unlink) the temporary file. There is a small example on the zlib [php.net] manual page except that instead of writing output to the browser, send appropriate header [php.net] lines and the file contents, then unlink.

dreamcatcher

6:22 pm on May 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Coop, that was exactly what I was referring to.

Sorry for not being clearer.

dc