PHP file download can not send POST data on the same form

advertisements

I have a basic username & password form which also allows you to upload an image with it. There's a create button, which takes the user to uploader.php which both uploads the image and inputs the username & password into the database.

Within the form tag:

< form enctype="multipart/form-data" method="POST" action="uploader.php?uploader=avatar&username=< ?php echo $_POST['username']; ?>" >

The problem:

The username won't post, nor any other posts for that matter. All fields are inside the form. I have checked PHP file upload form cannot submit a POST variable? and within php.ini post_max_size = 8M, and upload_max_filesize = 2M


Use <input type="hidden"/> to post username and other info.

<form enctype="multipart/form-data" method="POST" action="uploader.php">
    <input type="hidden" name="uploader" value="avatar"/>
    <input type="hidden" name="username" value="<?php echo $_POST['username']; ?>" />
    ...
</form>

Sample.php

<form enctype="multipart/form-data" method="POST" action="uploader.php">
  <br/>Username : <input type="text" name="username"/>
  <br/>Password : <input type="password" name="password"/>
    <input type="hidden" name="uploader" value="avatar"/>
   <br/>File : <input type="file" name="file"/>
   <br/><input type="submit"/>
</form>

uploader.php

<?php
  print_r($_POST)  // debug  $_POST
  print_r($_FILES) // file

  //OR
  echo $_POST["username"];
  $file=$_FILES["file"];
  print_r(file);
?>