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

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
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?>