久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在PHP中刪除所有超過2天的文件的正確方法

The correct way to delete all files older than 2 days in PHP(在PHP中刪除所有超過2天的文件的正確方法)
本文介紹了在PHP中刪除所有超過2天的文件的正確方法的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

只是好奇

        $files = glob(cacheme_directory()."*");
        foreach($files as $file)
        {
            $filemtime=filemtime ($file);
            if (time()-$filemtime>= 172800)
            {
                unlink($file);
            }
        }

我只想確定代碼是否正確.謝謝.

I just want to make sure if the code is correct or not. Thanks.

推薦答案

你應(yīng)該添加一個(gè) is_file() 檢查,因?yàn)?PHP 通常會(huì)列出 ...,以及可能駐留在您正在檢查的目錄中的子目錄.

You should add an is_file() check, because PHP normally lists . and .., as well as sub-directories that could reside in the the directory you're checking.

此外,正如此答案所建議的,您應(yīng)該用更具表現(xiàn)力的符號(hào)替換預(yù)先計(jì)算的秒數(shù).>

Also, as this answer suggests, you should replace the pre-calculated seconds with a more expressive notation.

<?php
  $files = glob(cacheme_directory()."*");
  $now   = time();

  foreach ($files as $file) {
    if (is_file($file)) {
      if ($now - filemtime($file) >= 60 * 60 * 24 * 2) { // 2 days
        unlink($file);
      }
    }
  }
?>

或者,您也可以使用 DirectoryIterator、如本答案所示.在這種簡單的情況下,它并沒有真正提供任何優(yōu)勢,但它會(huì)是 OOP 方式.

Alternatively you could also use the DirectoryIterator, as shown in this answer. In this simple case it doesn't really offer any advantages, but it would be OOP way.

這篇關(guān)于在PHP中刪除所有超過2天的文件的正確方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個(gè)表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動(dòng)填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 亚洲精品一区二区在线观看 | 成人在线电影在线观看 | 奇米影视在线 | 亚洲成人99 | 久久久噜噜噜久久中文字幕色伊伊 | 国产精品福利网站 | 日本aaaa| h视频免费在线观看 | 男女视频在线免费观看 | 久久性| 美女久久 | 97精品一区二区 | 午夜在线免费观看视频 | 91偷拍精品一区二区三区 | 亚洲一区二区免费 | 久久精品国产免费 | 久久精品91久久久久久再现 | 久久精品欧美一区二区三区不卡 | 蜜桃在线一区二区三区 | 国产日日操| 国产片侵犯亲女视频播放 | 国产成人麻豆免费观看 | 国产精品小视频在线观看 | 欧美黄在线观看 | 欧美老妇交乱视频 | 欧美日韩国产三级 | 成人在线免费观看视频 | 国产精品成人一区 | 狠狠久| 欧美性久久 | 欧美日韩在线成人 | 久久综合一区 | 久久精品国产免费一区二区三区 | 欧美性极品xxxx做受 | 日本一区二区高清视频 | 美女视频. | 欧美色性 | 久久久久久久久99 | 国精产品一品二品国精在线观看 | 激情五月综合 | 2019中文字幕视频 |