clear and delete the folder after the time specified in php

Solutions on MaxInterview for clear and delete the folder after the time specified in php by the best coders in the world

showing results for - "clear and delete the folder after the time specified in php"
Antonio
07 Jan 2020
1<?
2$days = 1;
3$dir = dirname ( __FILE__ );
4
5$nofiles = 0;
6
7    if ($handle = opendir($dir)) {
8    while (( $file = readdir($handle)) !== false ) {
9        if ( $file == '.' || $file == '..' || is_dir($dir.'/'.$file) ) {
10            continue;
11        }
12
13        if ((time() - filemtime($dir.'/'.$file)) > ($days *86400)) {
14            $nofiles++;
15            unlink($dir.'/'.$file);
16        }
17    }
18    closedir($handle);
19    echo "Total files deleted: $nofiles \n";
20}
21?>