12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace Controller;
- class LogController
- {
- const FIELDS = 4;
- public function downloadFileLog($startDate, $stopDate, $header)
- {
- $file = \Core\Log\FileLog::getFile();
- header("Content-Type: text/csv");
- header("Content-Disposition: attachment; filename=" . basename(str_replace('.log', '.csv', $file)));
- header("Cache-Control: no-cache, no-store, must-revalidate");
- header("Pragma: no-cache");
- header("Expires: 0");
-
- $output = fopen("php://output", "w");
- if (file_exists($file)) {
- $f = fopen($file, "r");
- fputcsv($output, $header);
- while(!feof($f)) {
- $row = explode(\Core\Log\FileLog::DATA_SEPARATOR, fgets($f));
- $rowDate = date('Y-m-d', strtotime($row[0]));
- if(
- count($row) == self::FIELDS &&
- strtotime($rowDate) >= strtotime($startDate) &&
- strtotime($rowDate) <= strtotime($stopDate)
- )
- {
- $row[0] = date('d.m.Y H:i:s', strtotime($row[0]));
- fputcsv($output, array_slice($row, 0, self::FIELDS - 1));
- }
- }
- fclose($output);
- fclose($f);
- exit;
- } else {
- throw new \Exception('Error');
- }
- }
- public function clearFileLog()
- {
- $file = \Core\Log\FileLog::getFile();
- if (file_exists($file) && filesize($file) > 0) {
- $f = fopen($file, "w+");
- fclose($f);
- } else {
- throw new \Exception('Error');
- }
- }
- }
|