Bird
0
0

What will the following PHP code output if the file 'example.txt' exists and is 150 bytes in size?

medium📝 Predict Output Q13 of 15
PHP - File Handling
What will the following PHP code output if the file 'example.txt' exists and is 150 bytes in size?
$file = 'example.txt';
if (file_exists($file)) {
    echo filesize($file);
} else {
    echo 'File not found';
}
A150
BError
C0
DFile not found
Step-by-Step Solution
Solution:
  1. Step 1: Check file existence

    The code uses file_exists() to confirm 'example.txt' exists, which it does.
  2. Step 2: Output file size

    Since the file exists, filesize($file) returns 150, which is printed.
  3. Final Answer:

    150 -> Option A
  4. Quick Check:

    File exists, output size = 150 [OK]
Quick Trick: filesize() returns size only if file_exists() is true [OK]
Common Mistakes:
  • Assuming filesize() works without checking existence
  • Confusing filesize() output with file content
  • Expecting 'File not found' when file exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes