What is the recommended method for automatically deleting inactive data in a PHP download center after a certain period of time?

To automatically delete inactive data in a PHP download center after a certain period of time, you can create a script that runs on a scheduled basis (e.g., using cron jobs) to check the last accessed timestamp of each file and delete files that have not been accessed for a specified period. You can use PHP's filemtime() function to get the last modified time of a file and compare it with the current time to determine if it should be deleted.

<?php
// Specify the directory where the files are stored
$directory = '/path/to/download/files/';

// Specify the period of inactivity in seconds (e.g., 30 days)
$inactivePeriod = 30 * 24 * 60 * 60;

// Get the list of files in the directory
$files = glob($directory . '*');

foreach ($files as $file) {
    // Get the last modified time of the file
    $lastAccessed = filemtime($file);

    // Calculate the time elapsed since last accessed
    $elapsedTime = time() - $lastAccessed;

    // Check if the file is inactive and delete it
    if ($elapsedTime > $inactivePeriod) {
        unlink($file);
        echo 'Deleted: ' . $file . PHP_EOL;
    }
}
?>