Check whether the code is correct and delete the data and files a month ago. In theory, the code is correct, but for fear ...... It's not fun to delete files or data wrong ...... Experts, can you tell me whether the following code is correct? PHPcoderequire (dirname (_ FILE __). & quot ;.. conn. php & quot;); mysql_select_db (& quot; news & quot;, $ co helps you check whether the code is correct and delete data and files from a month ago.
In theory, the code is correct, but for fear ......
It's not fun to delete files or data wrong ......
Experts, can you tell me whether the following code is correct?
PHP code
require (dirname(__FILE__) . "/../conn.php");mysql_select_db("news",$conn_database);mysql_query("delete from web_news where news_date<(date(now())-60*60*24*30)");mysql_close($conn_database);if ($handle = opendir(dirname(__FILE__).'/../cache/')) { while (false !== ($file = readdir($handle))) { if ((time()-filectime(dirname(__FILE__).'/../cache/'.$file)) < 60*60*24*30) { if (strripos($file, '.html') !== false) { unlink(dirname(__FILE__).'/../cache/'.$file); } } }}
------ Solution --------------------
Filectime
Should be changed
Filemtime
You can comment out unlink (dirname (_ FILE _). '/../cache/'. $ file );
Change
$ Fn = dirname (_ FILE _). '/../cache/'. $ file;
Echo $ fn. '-'. filemtime ($ fn );
Check it first
------ Solution --------------------
Ignored. do not pay attention to the database
(Date (now ()-60*60*24*30)
Change
DATE_SUB (now (), INTERVAL 30 DAY)
Select again.