title: PHP - File-Uploader
body: <p>I want to create a file-uploader with php.
  Does anybody know where the problem is. I am writing this code for the 3rd time, but it does not work...
  Can anybody help me???
  Thank you!!!</p>
  
  <p>HTML-File:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;title&gt;File Uploader&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;form action="upload_files.php" method="post" enctype="multipart/formdata"&gt;
          &lt;input type="file" name="file" /&gt;
          &lt;input type="submit" value="upload" /&gt;
      &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>PHP-File:</p>
  
  <pre><code>&lt;?php
  
      if (isset($_FILES['file'])) {
          $file = $_FILES['file'];
  
          $file_name = $file['name'];
          $file_tmp = $file['file_tmp'];
          $file_size = $file['size'];
          $file_error = $file['error'];
  
          $file_ext = explode('.', $file_name);
          $file_ext = strtolower(end($file_ext));
  
          $allowed = array('txt', 'jpg');
  
          if (in_array($file_ext, $allowed)) {
              if ($file_error === 0) {
                  $file_new_name = uniqid('', true) . '.' . $file_ext;
                  $file_dir = 'uploads/' . $file_new_name;
  
                  if (move_uploaded_file($file_tmp, $file_dir)) {
                      echo $file_dir;
                  }
              }
          }
      }
  
      ?&gt;
  </code></pre>