How can scandir() be modified or extended to include additional pairs like creation date and file type?
The scandir() function in PHP can be modified or extended by using the stat() function to retrieve additional file information such as creation date and file type. By obtaining the file's stat information, we can extract details like creation time and file type, and then include this information in the output of scandir().
$directory = '/path/to/directory';
$files = scandir($directory);
foreach ($files as $file) {
if ($file != '.' && $file != '..') {
$fileInfo = stat($directory . '/' . $file);
$creationDate = date('Y-m-d H:i:s', $fileInfo['ctime']);
$fileType = filetype($directory . '/' . $file);
echo "File: $file | Creation Date: $creationDate | File Type: $fileType <br>";
}
}