title: PHP file upload wrong file name encoding
body: <p>Im doing a webpage and have a problem with file upload, that changes the file name umlauts into a weird name.</p>
  
  <p>For example when i upload a file called "töö.docx" and look at the name in the uploaded folder, it shows me this "tĆ¶Ć¶.docx". </p>
  
  <p>When i call out the name of the file in index.php it shows me the correct name "töö.docx".</p>
  
  <p>But after i go into the upload folder and change the name "tĆ¶Ć¶.docx" manually into "töö.docx" and than call out the name of the file in index.php, it shows me "t��.docx" which is wrong. </p>
  
  <p>Here is the code for upload in index.php:</p>
  
  <pre><code>&lt;form method="post" enctype="multipart/form-data"&gt;
    &lt;strong&gt;File upload:&lt;/strong&gt;
    &lt;small&gt;(max 8 Mb)&lt;/small&gt;
    &lt;input type="file" name="fileToUpload" required&gt;
    &lt;input type="submit" value="Upload" name="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And here is the upload controller code:</p>
  
  <pre><code>$doc_list = array();
     foreach (new DirectoryIterator('uploads/') as $file)
  {
     if ($file-&gt;isDot() || !$file-&gt;isFile()) continue;
     $doc_list[] = $file-&gt;getFilename();
  }
  
  $target_dir = "uploads/";
  $target_file = $target_dir . basename( isset($_FILES["fileToUpload"]["name"]) ? $_FILES["fileToUpload"]["name"] : "");
  $file = isset($_FILES["fileToUpload"]) ? $_FILES["fileToUpload"] : "";
  $up_this = isset($_FILES["fileToUpload"]["tmp_name"]) ? $_FILES["fileToUpload"]["tmp_name"] : "";
  $file_name = isset($_FILES["fileToUpload"]["name"]) ? $_FILES["fileToUpload"]["name"] : "";
  
  if (!empty($file)) {
      if(isset($_POST["submit"])) {
          if (file_exists($file_name)) {
              echo "File already exists.";
              exit;
          } else {
              $upload =  move_uploaded_file($up_this, $target_file);
              if ($upload) {
                  echo "File ". '"' . basename($file_name). '"' . " has been uploaded";
              } else if (!$upload) {
                  echo "Could not upload file";
                  exit;
              }
          }
      }
  }
  </code></pre>
  
  <p>I use the variable $doc_list to call out the names of the documents in folder in index.php:</p>
  
  <pre><code>&lt;div&gt;
      &lt;?php if (!empty($doc_list)) foreach ($doc_list as $doc_name) { ?&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;?= $doc_name ?&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;?php } ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I've set the website charset into utf-8. and i still don't know why it's not displaying the correct file name with umlauts.</p>