<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Clear_logs extends CI_Controller {
public function __construct() {
parent::__construct();
// Load any required libraries, helpers, or models here
}
public function index() {
$log_path = APPPATH . 'logs/';
// Check if the directory exists
if (is_dir($log_path)) {
// Open the directory
if ($dh = opendir($log_path)) {
// Loop through all the files in the directory
while (($file = readdir($dh)) !== false) {
// Skip directories and non-log files
if ($file != '.' && $file != '..' && strpos($file, 'index.html') === false) {
// Delete the log file
@unlink($log_path . $file);
}
}
closedir($dh);
}
}
// Return a response or view
echo "Log files cleared!";
}
}
0 comments:
Post a Comment