Complete the code to check if the file 'example.txt' exists.
<?php if ([1]('example.txt')) { echo "File exists."; } else { echo "File does not exist."; } ?>
The file_exists function checks if a file or directory exists at the given path.
Complete the code to check if 'data.csv' is a regular file.
<?php if ([1]('data.csv')) { echo "It's a regular file."; } else { echo "It's not a regular file."; } ?>
The is_file function returns true if the path is a regular file.
Fix the error in the code to get the size of 'report.pdf'.
<?php $size = [1]('report.pdf'); echo "File size: $size bytes."; ?>
The filesize function returns the size of the file in bytes.
Fill both blanks to check if 'image.png' is readable and writable.
<?php if ([1]('image.png') && [2]('image.png')) { echo "File is readable and writable."; } else { echo "File is not accessible for reading and writing."; } ?>
is_readable checks if the file can be read, and is_writable checks if it can be written.
Fill all three blanks to create an array with file names and their sizes for files larger than 1000 bytes in the 'docs' directory.
<?php $files = scandir('docs'); $result = []; foreach ($files as $file) { $path = 'docs/' . $[1]; if (is_file($path) && filesize($path) [2] 1000) { $result[[3]] = filesize($path); } } print_r($result); ?>
We use file to build the path, check if the size is greater than 1000 bytes with >, and use $file as the key in the result array.