Is there a way I can have 5 logs files cleared on a frontend, without emptying the file data manually or deleting them?
I want to add a button or such on a page that will empty them if possible.
Is there a way I can have 5 logs files cleared on a frontend, without emptying the file data manually or deleting them?
I want to add a button or such on a page that will empty them if possible.
You can not clear a file on your server on frontend. You can push a button on frontend and call a backend script.
w+ : Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
$handle = fopen ("/path/to/file.txt", "w+");
fclose($handle);
clearlogs.php
<?php
$logfiles = array(
"1-LOG.txt",
"2-LOG.txt",
"3-LOG.txt",
"4-LOG.txt",
"5-LOG.txt",
);
foreach ($logfiles as $logfile){
$clearlogs = @fopen("$logfile","r+");
@ftruncate($clearlogs, 0);
}
header("Location:logs.php");
?>
logs.php
<form action="clearlogs.php" method="POST">
LOGS <input type="submit" value="Clear Logs" />
</form>