Simple Upload Form Not Working


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.


  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.


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.

written by jackson

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <pre>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".
  • Lines and paragraphs break automatically.
  • E-Mail addresses are hidden with reCAPTCHA Mailhide.

More information about formatting options

Complete this form and then pat yourself on the back.