作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我写了这个 php 脚本来删除超过 24 小时的旧文件,但它删除了所有文件,包括较新的文件:
<?php
$path = 'ftmp/';
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ((time()-filectime($path.$file)) < 86400) {
if (preg_match('/\.pdf$/i', $file)) {
unlink($path.$file);
}
}
}
}
?>
最佳答案
<?php
/** define the directory **/
$dir = "images/temp/";
/*** cycle through all files in the directory ***/
foreach (glob($dir."*") as $file) {
/*** if file is 24 hours (86400 seconds) old then delete it ***/
if(time() - filectime($file) > 86400){
unlink($file);
}
}
?>
您还可以通过在 *(通配符)后添加扩展名来指定文件类型,例如
对于 jpg 图像使用:glob($dir."*.jpg")
对于 txt 文件,请使用:glob($dir."*.txt")
对于 htm 文件,使用:glob($dir."*.htm")
关于用于删除早于 24 小时的文件的 php 脚本,删除所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3126191/
我有一个 javascript 函数,可以执行以下操作; 它将日期编辑框设置为与另一个日期编辑相同的日期。但是我希望它将 txt_Testin
我有一个输入框,类型为“时间”。我想将迟到时间 (23:00pm) 作为最小值,将早期时间 (6:00am) 作为最大值 - 创建一个 23pm - 6am 的范围。 (即中午 11 点、中午 12
使用 Joda 时间并获得类似以下行为的最简单方法是什么: public boolean check( DateTime checkTime ) { DateTime someTime = n
我想计算 updated_at 比 created_at 早 2 小时的记录。 代码 $teLang = $kentekens->where('updated_at', '>', 'created_a
我是一名优秀的程序员,十分优秀!