超薄表单不传递带有图像信息的数组[关闭]

So I have an html form and it is passing my picture(the actual name), but that is all I can get. It shows an error when I try to get the tmp_name or anything of that sort.

Also, I can only get the name of the file if my html form has no declared enctype.

HTML

<form action="{{ urlFor('account.profile.post') }}" method="post" autocomplete="off">
  <!-- OTHER TEXT INPUTS THAT OUTPUT PERFECTLY FINE -->
  <div class="form-group">
    <label for="propic">Profile picture</label>
    <input type="file" id="propic" name="propic">
  </div>
</form>

PHP

if($app->request->params('propic') != null) {
  $propic = $app->request->post('propic');
  $target_dir = "profs/$img_salt/";
  $target_file = $target_dir.$propic;
  $uploadOk = 1;
  $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);

  if (move_uploaded_file($propic["tmp_name"], $target_file)) {
    echo "The file ". basename( $propic["name"]). " has been uploaded.";
  } else {
    echo "Sorry, there was an error uploading your file.";
  }
}

You have to set the encoding type of the form to multipart/form-data:

<form action="{{ urlFor('account.profile.post') }}" method="post" autocomplete="off" enctype="multipart/form-data">

Without this encoding type, you won't be able to send files with that form.

And in your php, grab the file from files instead of post (not sure if the following code is the way to do it in the php framework you are using):

$propic = $app->request->files('propic');