Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ahmethakanbesel
Created July 3, 2017 11:47
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 ahmethakanbesel/883cb762406cc77391807dbe97eb3d91 to your computer and use it in GitHub Desktop.
Save ahmethakanbesel/883cb762406cc77391807dbe97eb3d91 to your computer and use it in GitHub Desktop.
PHP ile eski dosyaları silme (Delete files older than X in PHP)
<?php
/*
* Silinecek dosyaların bulunduğu dizin
*/
$dir = "klasor/dosyalar";
/*
* Dizindeki tüm dosyalara işlem uygulanır
*/
foreach (glob($dir."*") as $file) {
/*
* 1 gün = 24 saat = 86400 saniye (bir günden eski tüm dosyaları siler
*/
if(time() - filectime($file) > 86400){
unlink($file);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment