What is the potential issue with sorting folders by upload date instead of folder name (which is a date) in PHP?

When sorting folders by upload date instead of folder name in PHP, the potential issue is that the sorting may not be accurate if the folder names do not accurately reflect the upload dates. To solve this issue, you can retrieve the folder names, extract the upload dates from the names, sort the dates, and then rearrange the folders based on the sorted dates.

$folders = scandir('path/to/folders');
$folderDates = [];

foreach ($folders as $folder) {
    if ($folder != '.' && $folder != '..') {
        $folderDates[$folder] = strtotime(str_replace('_', '-', $folder));
    }
}

asort($folderDates);

foreach ($folderDates as $folder => $date) {
    echo $folder . "\n";
}