简体   繁体   中英

php - how delete all files every 5min in x folder?

i think this code automatically creates a folder name (cache) and i want to delte files in this folder every 5 min, beaucose every time when somone play my video that folder have + a file!!!

//New cache

function gd_cache($link, $source) {
$time = gmdate('Y-m-d H:i:s', time() + 3600*(+7+date('I')));
$file_name = md5('AA'.$link.'A3Code');
$string = strtotime($time).'@@'.$source;
$file = fopen("cache/".$file_name.".cache",'w');
fwrite($file,$string);
fclose($file);

if(file_exists('cache/'.$file_name.'.cache')) {
    $msn = $source;
} else {
    $msn = $source;
}
return $msn;
}

In the if condition use unlink function on success

if(file_exists('cache/'.$file_name.'.cache')) {
   $msn = $source;
   unlink('cache/'.$file_name.'.cache');
} else {
   $msn = $source;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM