How can one display the file size and creation date for each file when using opendir() in PHP?

When using opendir() in PHP to read files from a directory, you can use the filemtime() function to get the creation date of each file. To display the file size, you can use the filesize() function. By combining these functions with the readdir() function to iterate through the files in the directory, you can display the file size and creation date for each file.

$dir = 'path/to/directory';
$dh = opendir($dir);

while (($file = readdir($dh)) !== false) {
    if ($file != '.' && $file != '..') {
        $filePath = $dir . '/' . $file;
        $fileSize = filesize($filePath);
        $fileCreationDate = date("Y-m-d H:i:s", filemtime($filePath));

        echo "File: $file | Size: $fileSize bytes | Creation Date: $fileCreationDate <br>";
    }
}

closedir($dh);