aboutsummaryrefslogtreecommitdiff
path: root/lib/export/export_tmp_gc.inc.php
blob: 62ab36b8b048a8b25e0de8701e6b8612106657b5 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
# Lifter002: TODO
# Lifter007: TODO
# Lifter003: TODO
# Lifter010: TODO
/**
* function to delete old files in the export tmp-directory.
* 
* This file checks the tmp-directory for old files an deletes them.
*
* @author       Arne Schroeder <schroeder@data.quest.de>
* @access       public
* @package      Export
*/
// +---------------------------------------------------------------------------+
// This file is part of Stud.IP
// oscar.inc.php
//
// Copyright (c) 2002 Arne Schroeder <schroeder@data-quest.de> 
// Suchi & Berg GmbH <info@data-quest.de>
// +---------------------------------------------------------------------------+
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
// +---------------------------------------------------------------------------+
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// +---------------------------------------------------------------------------+

function export_tmp_gc(){
    $tmp_export = $GLOBALS['TMP_PATH']. '/export/';
    if(!is_dir($tmp_export)){
        if(!mkdir($tmp_export)){
            trigger_error("tmp directory for export ($tmp_export) could not be created",E_USER_WARNING);
            return false;
        } else {
            chmod($tmp_export, 0700);
        }
    }
    if (mt_rand() % 100 < 10){
        $dir = @dir($tmp_export);
        if ($dir){
            while (false !== ($entry = $dir->read())) {
                // Skip pointers
                if ($entry == '.' || $entry == '..') {
                    continue;
                }
                $file = $tmp_export . '/' . $entry;
                $now = time();
                if (@is_file($file) && (($now - filemtime($file)) > 86400)){
                    @unlink($file);
                }
            }
            $dir->close();
        }
    }
}
?>