其實iam通過php在我創建的導出文件夾中轉儲數據庫文件。 在這裏,我想只保留最新的十個sql文件在導出文件夾類的FIFO方式。 我不想過度填充文件夾,並想限制它十個最新的文件。 如何做到這一點?如何限制一個文件夾的最大文件數
0
A
回答
-1
你可以取消鏈接功能刪除文件:http://php.net/manual/de/function.unlink.php
你只需要找到目錄中的最早的文件
0
首先抓住所有的文件使用glob
例如,然後確定是否有十個或目錄中有更多文件。之後,檢查mtime
(修改時間),並刪除最舊的一個。
$file_pattern = '/path/to/directory/and/files/*';
$filenames = glob($file_pattern);
if (count($filenames) > 9) {
// While there are ten or more files.
while (count(glob($file_pattern)) > 9) {
$oldest_file = null;
// Grab the unix timestamp of *now*, as filemtime returns a unix timestamp too.
$current_oldest_time = time();
foreach ($filenames as $filename) {
$filetime = filemtime($filename);
if ($filetime < $current_oldest_time) {
$current_oldest = $filetime;
$oldest_file = $filename;
}
}
// After the foreach you'll have the filename of the oldest file (remove it),:
unlink($oldest_file);
// Or null if something went wrong (break out of the loop):
break;
}
}
相關問題
- 1. VB6,如何限制文件夾大家
- 2. PowerShell的最新文件夾複製到另一個文件夾
- 3. np.fromfile文件大小的最大限制?
- 4. 本地文件夾的大小限制?
- 5. 限制用戶的文件夾大小
- 6. 限制文件夾
- 7. 如何限制rtMedia 3.7 wordpress插件的最大文件大小限制?
- 8. 如何將文件從一個文件夾複製到另一個文件夾
- 9. 在一個文件夾中可以上傳到SharePoint位置的文件的最大數量是否有限制
- 10. 如何限制訪問的文件夾
- 11. elFinder限制文件夾大小
- 12. 下載帶有最大文件大小限制的.zip文件
- 13. 是否有.csv文件的最大文件大小硬限制?
- 14. 最大的文件上傳限制PHP
- 15. 限制WebClient下載文件最大文件大小
- 16. 如何限制文件夾給用戶
- 17. 如何限制文件夾深度?
- 18. 如何限制文件夾訪問
- 19. 如何限制SVN文件夾?
- 20. 將文件夾從一個文件夾複製到一個新文件夾
- 21. 如何限制對codeigniter文件夾中的文件的訪問
- 22. 如何限制文件夾/子文件夾/文件只能訪問程序?
- 23. 將文件夾的權限克隆到另一個文件夾
- 24. 如何將一百個文件從文件夾複製到文件夾?
- 25. 如何將文件夾和子文件夾中的文件複製到R中的另一個文件夾?
- 26. 保存用戶圖像 - 達到最大文件夾限制
- 27. Linux的 - 如何將文件/文件夾複製沒有權限
- 28. 限制文件流的文件大小?
- 29. (節點)點擊最大文件限制?
- 30. 最大文件上傳限制
使用與轉儲數據庫文件相同的代碼刪除第11個文件。 – 2014-10-09 06:26:58