Auto delete all files after x-time

后端 未结 8 1402
春和景丽
春和景丽 2020-12-28 10:04

How do you auto delete all files under a sub directory after x-time (let say after 24 hours) - without using a cronjob command from server or pl. How can you do this just us

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-28 10:35

    After trying to use these examples, I hit a couple of issues:

    1. The comparison operator should be greater than, not less than
    2. filemtime returns the modified time. filectime is the time when a file's inode data is changed; that is, when the permissions, owner, group, or other metadata from the inode is updated, which may lead to unexpected results

    I changed the example to use filemtime and fixed the comparison as follows:

     86400) {  // 86400 = 60*60*24
              if (preg_match('/\.txt$/i', $file)) {
                unlink($path.'/'.$file);
              }
            }
        }
      }
    ?>
    

提交回复
热议问题