-
Notifications
You must be signed in to change notification settings - Fork 1
/
cleaning_support.php
73 lines (64 loc) · 2.27 KB
/
cleaning_support.php
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
65
66
67
68
69
70
71
72
73
<?php
/* configuration.php and stat_keeper.php are required before this */
/***************************************************************************
* Copyright (C) 2010 by Periklis Ntanasis , Ammar Qammaz *
*
* *
* 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 *
* (at your option) 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 check_if_its_too_soon_after_last_clean_operation()
{
if (!file_exists ("last_cleanup.ini"))
{
// AUTO GENERATION OF FILE :)
echo "Auto Generation of cleanup file!";
$file=fopen("last_cleanup.ini","w+");
fwrite($file,"");
fclose($file);
return 0; // NO FILE EXISTS MEANS NO CLEANUP HAS BEEN CALLED ( EVER )
}
else
{
/* TODO ADD CODE THAT CHECKS IF IT IS TOO SOON BY USING A FILE TO STORE LAST CLEAN UP DATE&TIME! */
}
return 0;
}
function check_and_clean_uploads()
{
if ( check_if_its_too_soon_after_last_clean_operation() == 1 ) return;
global $MAXIMUM_STAY_ON_SERVER_HOURS, $SCRIPT_LOCAL_BASE;
if($MAXIMUM_STAY_ON_SERVER_HOURS!=0)
{
$target=$SCRIPT_LOCAL_BASE."uploads/";
$files=scandir($target);
$now=date("U");
foreach($files as $file)
{
if(strcmp($file,"index.html")==0 || strcmp($file,"check_x.png")==0 || strcmp($file,".")==0 || strcmp($file,"..")==0 || strcmp($file,".htaccess")==0)
{
continue;
}
$fileseconds=date("U", filemtime($target.$file));
$filehours=($now - $fileseconds)/3600;
if($filehours>$MAXIMUM_STAY_ON_SERVER_HOURS)
{
remove_from_cache_size(filesize($target.$file));
unlink($target.$file);
}
}
}
}
?>