如果1天,请删除并更新文件

时间:2011-07-22 18:39:51

标签: php file

我正在用PHP编写代码,如果文件超过一天,它会删除一个文件。 但是我没有这样做,并在它之后追加:(

$fileName = 'news/'.$_COOKIE['sign'];
if (isset($_COOKIE['sign']))
{
 if ((file_exists($fileName)) && (date("d",filemtime($fileName))==date("d")))
 {
  $data = file_get_contents($fileName);
  if ($data == '')
  {
   $data = 'Temporary network problem !';
   unlink($fileName);
  }
  echo $data;
}
else
 echo 'Fetch and put new news';

1 个答案:

答案 0 :(得分:2)

$fileName = 'news/'.$_COOKIE['sign'];
if (isset($_COOKIE['sign'])) {
    if ((file_exists($fileName)) && (date("d", filemtime($fileName)) == date("d"))) {
        $data = file_get_contents($fileName);
        if ($data == '') {
            $data = 'Temporary network problem !';
            unlink($fileName);
        }
        echo $data;
    }
    elseif(file_exists($fileName)) { //if not above, then delete it!
        unlink($fileName);
    } 
    else {
        echo 'Fetch and put new news';
    }
}