我的data.txt是每次有人訪問我的網站時生成的。我想在特定的時間刪除這個文件,比如說每天凌晨1點。 我發現這個腳本,但我努力更新代碼:/ 有什麼建議嗎?如何從特定時間的目錄中刪除文件,每天?
<?php
$path = dirname(__FILE__).'/files';
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ((time()-filectime($path.'/'.$file)) < 86400) { // 86400 = 60*60*24
if (preg_match('/\.txt$/i', $file)) {
unlink($path.'/'.$file);
}
}
}
}
?>
what os? * nix =>嘗試使用cron作業 – bansi
爲什麼你想用PHP來做到這一點?使用cron作業並使用文件系統刪除文件。 – vascowhite