Skip to content

Instantly share code, notes, and snippets.

@mikaelz
Created May 7, 2015 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikaelz/da482437e523bc249cf4 to your computer and use it in GitHub Desktop.
Save mikaelz/da482437e523bc249cf4 to your computer and use it in GitHub Desktop.
Remove expired, outdated files by checking inode change time https://php.net/manual/en/directoryiterator.getctime.php
if (is_dir(TEMP_PATH)) {
foreach (new DirectoryIterator(TEMP_PATH) as $fileInfo) {
if ($fileInfo->isDot()) {
continue;
}
if (time() - $fileInfo->getCTime() >= HOUR_IN_SECONDS) {
unlink($fileInfo->getRealPath());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment