How does the readdir function in PHP impact the file path when displaying images?

When using the readdir function in PHP to read files in a directory, the file path returned may not be in the correct format for displaying images. To solve this issue, you can concatenate the directory path with the file name to create the correct file path for displaying images.

$directory = "images/";
$files = scandir($directory);

foreach($files as $file) {
    if ($file != "." && $file != "..") {
        echo '<img src="' . $directory . $file . '" alt="image">';
    }
}