我正在用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';
答案 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';
}
}