title: Undefined index error in PHP while uploading file
body: <p>I have such a form for uploading files and creating new directories:</p>
  
  <pre><code>&lt;form  action="files.php"  method="POST"&gt;
  &lt;div class="row btn-row"&gt;
       &lt;div class="col-xs-3"&gt;
            &lt;input type="text" class="form-control" id="mkdir-name" placeholder="New directory name" size="10"&gt;
       &lt;/div&gt;
  
       &lt;input type="submit" class="btn btn-success my-btn" value="Create folder" name="mkdir"&gt;
       &lt;input type="submit" class="btn btn-danger my-btn" value="Delete folder" name="remdir"&gt;
       &lt;/div&gt;
  &lt;div class="row btn-row"&gt;
       &lt;div class="col-xs-3"&gt;
            &lt;input type="hidden" name="MAX_FILE_SIZE" value="1024000"&gt;
            &lt;input name="userfile" type="file" class="my-btn"&gt;
       &lt;/div&gt;
       &lt;input type="submit" class="btn btn-success my-btn" value="Upload file" name="upfile"&gt;
       &lt;input type="submit" class="btn btn-danger my-btn" value="Delete file" name="delfile"&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>The corresponding files.php script is quite simple:</p>
  
  <pre><code>    &lt;?php
  //Start new or resume existing session
      session_start();
      if(isset($_POST['upfile'])){
          $target_dir = $_SESSION["current-directory"]."/";
          $target_file = $target_dir . basename($_FILES["userfile"]["name"]);
          if (move_uploaded_file($_FILES['userfile']['tmp_name'], $target_file)) {
              echo "File is valid, and was successfully uploaded.\n";
          } else {
              echo "Possible file upload attack!\n";
          }
      }
  ?&gt;
  </code></pre>
  
  <p>I'm really new in PHP but I'm completly following different tutorials from w3school and php.net. I'm getting the following errors:</p>
  
  <blockquote>
    <p>Notice: Undefined index: userfile in
    C:\wamp\www\webspace\php\files.php on line 6 Notice: Undefined index:
    userfile in C:\wamp\www\webspace\php\files.php on line 7</p>
  </blockquote>
  
  <p>I have no idea what can cause this problem. </p>