-
Notifications
You must be signed in to change notification settings - Fork 17
/
cleaner.php
28 lines (28 loc) · 1.08 KB
/
cleaner.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
<?php
$maxAge=-1;// max age in seconds, scans older that this will be deleted; negative values disable cleaning
if(isset($_GET['file'])){
if(is_numeric(strrpos($_GET['file'], "/")))
$_GET['file']=substr($_GET['file'],strrpos($_GET['file'],"/")+1);
$file=$_GET['file'];
$file0=substr($file,0,strrpos($file,"."));
echo '{"state":'.((@unlink("scans/thumb/Preview_$file0.jpg")&&@unlink("scans/file/Scan_$file"))?0:1).',"file":"'.$file.'"}';
}
else if($maxAge>-1){
echo "<pre>\n";
$loc=$_SERVER['DOCUMENT_ROOT'].str_replace('cleaner.php','scans/file',$_SERVER['SCRIPT_NAME']);
$lst=scandir($loc);
for($i=2,$max=count($lst);$i<$max;$i++){
if($lst[$i]!='.'&&$lst[$i]!='..'){
if(time()-filemtime("$loc/".$lst[$i])>$maxAge){
//copy("$loc/".$lst[$i], '/path/to/archive/');// www-data require write acceess to the archive
if(@unlink("$loc/".$lst[$i]))
echo "Removed: $loc/".$lst[$i]."\n";
$lst[$i]='Preview_'.substr($lst[$i],5,strrpos($lst[$i],'.')-5).'.jpg';
if(@unlink("$loc/../thumb/".$lst[$i]))
echo "Removed: $loc/../thumb/".$lst[$i]."\n";
}
}
}
echo "</pre>";
}
?>