-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_logger.php
More file actions
36 lines (32 loc) · 999 Bytes
/
new_logger.php
File metadata and controls
36 lines (32 loc) · 999 Bytes
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
<?php
date_default_timezone_set('Europe/Berlin');
$timestamp = time();
$date = date('Y-m-d',$timestamp);
$time = date('H:i:s',$timestamp);
$status = filter_var($_GET['status'], FILTER_SANITIZE_STRING);
$file = 'NEW40-Log.txt';
$zipfile = 'NEW40-Log-'.$timestamp.'.zip';
$sizemax = 1024000; // 1 MB, then zip it
if(empty($status)){
die('No status set, no data written to file');
}
# if the $file > than $sizemax, then zip and delete the old textfile
if (file_exists($file)) {
$size = filesize($file);
if ($size > $sizemax) {
$zip = new ZipArchive;
if ($zip->open($zipfile, ZipArchive::CREATE) === TRUE){
$zip->addFile($file);
$zip->close();
}
unlink($file);
}
}
$str = $date . " | " . $time . " | " . $status . "\n";
$content = (file_exists($file)) ? file_get_contents($file) : '';
$str = utf8_decode($str);
$handle = fopen($file, 'w');
fwrite($handle, $str . $content);
fclose($handle);
exit();
?>