Bird
0
0

Which of the following is the correct syntax to check if a file was uploaded without errors using $_FILES?

easy📝 Syntax Q3 of 15
PHP - Superglobals and Web Context
Which of the following is the correct syntax to check if a file was uploaded without errors using $_FILES?
Aif ($_FILES['file']['size'] === 0) {}
Bif ($_FILES['file']['error'] === 0) {}
Cif ($_FILES['file']['tmp_name'] === '') {}
Dif ($_FILES['file']['name'] === null) {}
Step-by-Step Solution
Solution:
  1. Step 1: Understand the 'error' key in $_FILES

    The 'error' key holds an integer code; 0 means no error during upload.
  2. Step 2: Check correct syntax for error check

    Using strict equality to 0 confirms the file uploaded successfully without errors.
  3. Final Answer:

    if ($_FILES['file']['error'] === 0) {} -> Option B
  4. Quick Check:

    Error code 0 means success [OK]
Quick Trick: Check 'error' === 0 to confirm successful upload [OK]
Common Mistakes:
  • Checking 'size' === 0 to confirm upload
  • Checking 'tmp_name' for empty string incorrectly
  • Using 'name' === null which is never null

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes