Answers for "Clear and delete the folder after the time specified in php"

PHP
0

Clear and delete the folder after the time specified in php

<?
$days = 1;
$dir = dirname ( __FILE__ );

$nofiles = 0;

    if ($handle = opendir($dir)) {
    while (( $file = readdir($handle)) !== false ) {
        if ( $file == '.' || $file == '..' || is_dir($dir.'/'.$file) ) {
            continue;
        }

        if ((time() - filemtime($dir.'/'.$file)) > ($days *86400)) {
            $nofiles++;
            unlink($dir.'/'.$file);
        }
    }
    closedir($handle);
    echo "Total files deleted: $nofiles \n";
}
?>
Posted by: Guest on August-07-2020

Code answers related to "Clear and delete the folder after the time specified in php"

Browse Popular Code Answers by Language