Re: Delete a file after it has been downloaded?
| From: | Matt M. | Date: | Wed, 18 Aug 2004 22:10:59 +0000 |
| Subject: | Re: Delete a file after it has been downloaded? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-194200@lists.php.net to get a copy of this message | ||
On Wed, 18 Aug 2004 23:56:57 +0200, Yngve <kentnntp@mds.mdh.se> wrote:
> Hi!
>
> I wonder if it´s possible (and how) to delete a file after it has been
> downloaded, without running anything on the server except for the PHP page
> which the user gets the file from.
>
> If it is not possible, i wonder how i could create a script which deletes
> all files in a directory which are more than 5 hours old?
http://us3.php.net/unlink
or something like this
define(FILE_DIRECTORY , path to your directory);
define(DELETE_TIME , 18000); //5 hours
$current_time = time();
// Open a known directory, and proceed to read its contents
if (is_dir(FILE_DIRECTORY)) {
if ($dh = opendir(FILE_DIRECTORY)) {
while (($file = readdir($dh)) !== false) {
if (is_file(FILE_DIRECTORY.$file) ) {
$file_time = filectime ( FILE_DIRECTORY.$file );
if ($current_time - $file_time > DELETE_TIME ) {
unlink(FILE_DIRECTORY.$file);
}
}
}
closedir($dh);
}
}