42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
||
use Illuminate\Support\Facades\Storage;
|
||
use Carbon\Carbon;
|
||
|
||
// CSRF token kontrolü
|
||
if (!isset($_POST['_token']) || !csrf_token()) {
|
||
echo json_encode(['status' => 'error', 'message' => 'CSRF token error']);
|
||
exit();
|
||
}
|
||
|
||
try {
|
||
// Bugünün tarihini al
|
||
$today = Carbon::today()->format('Y-m-d');
|
||
$logsPath = storage_path('logs');
|
||
$deletedCount = 0;
|
||
|
||
// Tüm log dosyalarını tara
|
||
$logFiles = glob($logsPath . '/*.log');
|
||
|
||
foreach ($logFiles as $logFile) {
|
||
$fileName = basename($logFile);
|
||
// Laravel log dosya formatı: laravel-YYYY-MM-DD.log
|
||
if (preg_match('/truncgil-' . $today . '\.log$/', $fileName)) {
|
||
if (unlink($logFile)) {
|
||
$deletedCount++;
|
||
}
|
||
}
|
||
}
|
||
|
||
echo json_encode([
|
||
'status' => 'success',
|
||
'message' => $deletedCount . ' log files have been successfully deleted',
|
||
'deleted_count' => $deletedCount
|
||
]);
|
||
|
||
} catch (Exception $e) {
|
||
echo json_encode([
|
||
'status' => 'error',
|
||
'message' => 'An error occurred while deleting log files: ' . $e->getMessage()
|
||
]);
|
||
}
|
||
?>
|