-1

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.

John Conde
  • 217,595
  • 99
  • 455
  • 496
KJThaDon
  • 416
  • 3
  • 15

2 Answers2

1

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);

Wim
  • 41
  • 3
0

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>
KJThaDon
  • 416
  • 3
  • 15