注意:未定义索引:filetoUpload [重复]

This question already has an answer here:

Okay, so I am trying to build a system where an admin can upload files for people of other departments working in a company. So I was working on the php file upload script but i keep getting this Error

Notice: Undefined index: filetoUpload

Here's my code.

Index.html

<form class="form-group" method="POST" action="upload.php">
    <select class="form-control col-sm-6" name="department">
      <option>Department</option>
      <option>HR</option>
      <option>Engineering</option>
      <option>Finance</option>
      <option>HR Forms</option>
      <option>IT</option>
      <option>Learning Center Other</option>
      <option>Learning Center Technical</option>
      <option>Marketing</option>
      <option>Operations</option>
      <option>Processe<s/option>
      <option>Other</option>
    </select><br>
    <input type="file" name="fileToUpload" value="Choose File" id="fileToUpload" class="btn btn-info"><br>
    <input type="submit" name="btn" class="btn btn-primary" value="Upload" style="margin-top: 10px;">
  </form>

upload.php

<?php

$department = $_POST['department'];
$file = $_FILES['fileToUpload']['name'];
echo  $department . $file;

?>

</div>

Use multipart/form-data if the form contains a file upload. The enctype attribute specifies how the form-data should be encoded when submitting it to the server.

So your form should be like this:

<form class="form-group" method="POST" action="upload.php" enctype="multipart/form-data">
    <select class="form-control col-sm-6" name="department">
      <option>Department</option>
      <option>HR</option>
      <option>Engineering</option>
      <option>Finance</option>
      <option>HR Forms</option>
      <option>IT</option>
      <option>Learning Center Other</option>
      <option>Learning Center Technical</option>
      <option>Marketing</option>
      <option>Operations</option>
      <option>Processe<s/option>
      <option>Other</option>
    </select><br>
    <input type="file" name="fileToUpload" value="Choose File" id="fileToUpload" class="btn btn-info"><br>
    <input type="submit" name="btn" class="btn btn-primary" value="Upload" style="margin-top: 10px;">
  </form>