Bird
0
0

You want to check if a file 'data.csv' exists, is readable, and its size is greater than 0 bytes before processing it. Which PHP code correctly performs all these checks?

hard📝 Application Q8 of 15
PHP - File Handling
You want to check if a file 'data.csv' exists, is readable, and its size is greater than 0 bytes before processing it. Which PHP code correctly performs all these checks?
Aif (file_exists('data.csv') && filesize('data.csv') == 0) { echo 'Ready'; }
Bif (file_exists('data.csv') && is_readable('data.csv') && filesize('data.csv') > 0) { echo 'Ready'; }
Cif (is_file('data.csv') || is_readable('data.csv') || filesize('data.csv') > 0) { echo 'Ready'; }
Dif (is_dir('data.csv') && is_readable('data.csv')) { echo 'Ready'; }
Step-by-Step Solution
Solution:
  1. Step 1: Combine all required checks with AND

    We need to ensure the file exists, is readable, and size is greater than zero, so use && between conditions.
  2. Step 2: Verify each function usage

    file_exists() checks existence, is_readable() checks read permission, filesize() > 0 checks size positive.
  3. Final Answer:

    if (file_exists('data.csv') && is_readable('data.csv') && filesize('data.csv') > 0) { echo 'Ready'; } -> Option B
  4. Quick Check:

    All conditions combined with AND for file readiness [OK]
Quick Trick: Use && to combine all file checks correctly [OK]
Common Mistakes:
  • Using || instead of &&
  • Checking filesize == 0 instead of > 0
  • Using is_dir() for files

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes