1<?php
2 $directory = ".";
3
4 $files = array();
5 foreach(scandir($directory) as $file){
6 if(is_file($file)) {
7
8 //get all the files
9 $files[$file] = filemtime($file);
10 }
11 }
12
13 //sort descending by filemtime;
14 arsort($files);
15 $count = 1;
16 foreach ($files as $file => $time){
17 if($count > 10){
18 unlink($file);
19 }
20 $count++;
21 }
22