Complete the code to open a directory named 'files'.
<?php $dir = [1]('files'); ?>
The opendir function opens a directory handle for reading its contents.
Complete the code to read an entry from the directory handle.
<?php $dir = opendir('files'); $file = [1]($dir); ?>
The readdir function reads the next entry from an open directory handle.
Fix the error in the code to properly close the directory handle.
<?php $dir = opendir('files'); // some code [1]($dir); ?>
The closedir function closes an open directory handle.
Fill both blanks to create an array of files in the 'docs' directory and check if it contains 'readme.txt'.
<?php $files = [1]('docs'); if (in_array([2], $files)) { echo 'Found readme.txt'; } ?>
scandir returns an array of files in a directory. We check if 'readme.txt' is in that array.
Fill all three blanks to loop through the 'images' directory and print each file name except '.' and '..'.
<?php $dir = opendir('images'); while (($file = [1]($dir)) !== false) { if ($file != [2] && $file != [3]) { echo $file . "\n"; } } closedir($dir); ?>
readdir reads each entry. We skip the special entries '.' and '..' which represent current and parent directories.