Boa tarde, criei um arquivo PHP com comandos MySql para excluir registros no BD com data maior que 7 dias e uma função que exclui arquivos de imagens talbém com mais de 7 dias no caminho especificado.
<?php include_once 'db_connect.php'; include_once 'functions.php'; /* DELETE REGISTERS WITH MORE THAN 7 DAYS */ $sql = "DELETE FROM tabela WHERE date < DATE_SUB(NOW(), INTERVAL 7 DAY);"; $result = $mysqli->query($sql); /* DELETE FILES WITH MORE THAN 7 DAYS */ $path = "../arquivos/"; if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { $filelastmodified = filemtime($path . $file); if((time() - $filelastmodified) > 7*24*3600) { unlink($path . $file); } } closedir($handle); } ?>
Qual seria a melhor maneira de fazer esse arquivo ser executado? Sei que com os comandos MySql posso fazer um trigger, mas já que tenho uma função também, acho que seria melhor executar esse arquivo php.
Se eu fizer um include(); no index.php do website, vai funcionar? Seria esse o melhor jeito?