1

When PHP code

error_log("1. Error: " . $_FILES['uploaded_file1']['error']);

prints

"... stderr: PHP message: 1.Error: "

what does it mean? I expect that $_FILES['uploaded_file1']['error'] will return Error code from 0-8 and not Nothing.

2
  • Does var_dump($_FILES['uploaded_file1']) show any content? It's possible that file field doesn't exist in the submitted data (either because there is no field with that name on the form or because it wasn't submitted with the right enctype, or for some other reason). Certainly if I tried to access $_FILES['lalalalalafoobar']['error'] that wouldn't exist either. Commented Mar 23, 2016 at 21:08
  • Yes, now I see that there is nothing. I just expect, if there is nothing I will receive error code UPLOAD_ERR_NO_FILE. Commented Mar 23, 2016 at 21:13

1 Answer 1

1

PHP only populates $_FILES with keys that actually exist on the form. Imagine if it didn't. It would have to create $_FILES['a'], $_FILES['aa'], $_FILES['aaaaaaaaaaaa'] — in fact, it would have to fill in every possible field name in the universe (which is infinitely many) on the off chance you might try to look for an error code on one of them.

You should first check to see if isset($_FILES['uploaded_file1']) which tells you if PHP even attempted to look for a file with that name. If it's missing, that's not the same thing as UPLOAD_ERR_NO_FILE.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.