How can PHP be used to automatically delete files in a folder at specified intervals?

To automatically delete files in a folder at specified intervals using PHP, you can create a script that runs on a scheduled basis (e.g., using a cron job) to check the files in the folder and delete them based on certain criteria such as file age or file type. This can help keep the folder clean and prevent it from becoming cluttered with unnecessary files.

<?php
$folder = '/path/to/folder';
$files = glob($folder . '/*');
$deleteInterval = 86400; // 1 day in seconds

foreach ($files as $file) {
    if (filemtime($file) < (time() - $deleteInterval)) {
        unlink($file);
        echo "Deleted file: $file\n";
    }
}
?>