Simple Upload Form Not Working

upload_file

I was putting together an upload form today that uploads to a file to PHP. On submit, the $_FILES var was empty and for the life of me I couldn’t figure out what was going on.

Attempts:

  1. I tried a print_r on both $_POST and $FILES. Both showed up empty.
  2. Added info to the $_GET to make sure the POST was even going to the action page.
  3. Made sure I had enctype=”multipart/form-data” in the form.

Solution:

Apparently for these forms to work, the input type=”file” also needs the name attribute. Once I added name=”file” the $_FILES var showed with upload data, just as it should. Anyway, I hope this saves someone some time.