Auto delete all files after x-time

后端 未结 8 1387
春和景丽
春和景丽 2020-12-28 10:04

How do you auto delete all files under a sub directory after x-time (let say after 24 hours) - without using a cronjob command from server or pl. How can you do this just us

8条回答
  •  天命终不由人
    2020-12-28 10:34

    $path = 'folder/subfolder/';
    
    /* foreach (glob($path.'.txt') as $file) { */
    foreach (glob($path.'*') as $file) {
    
        if(time() - filectime($file) > 86400){
          unlink($file);
        }
    }
    

提交回复
热议问题