forked from DistributedProofreaders/ppwb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaint3.php
More file actions
42 lines (37 loc) · 1.02 KB
/
maint3.php
File metadata and controls
42 lines (37 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/* this script is run by cron daily to remove any log files in
the 't' subdirectory older than 14 days.
crontab -e entry:
31 2 * * * wget -q --spider http://pgdp.org/~rfrank/ppwb/maint3.php
*/
function deleteDir($dirPath) {
if (! is_dir($dirPath)) {
throw new InvalidArgumentException("$dirPath must be a directory");
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
$fn = $dirPath . "images/.DS_Store";
if (file_exists($fn)) {
unlink $fn;
}
foreach ($files as $file) {
if (is_dir($file)) {
deleteDir($file);
} else {
unlink($file);
}
}
rmdir($dirPath);
}
$fileSystemIterator = new FilesystemIterator('t');
$now = time();
foreach ($fileSystemIterator as $file) {
if ($now - $file->getCTime() >= 60 * 60 * 24 * 14) {
echo('t/'.$file->getFilename());
echo "<br/>";
deleteDir('t/'.$file->getFilename());
}
}
?>