title: upload file to web server error 6 php
body: <p>I am trying to upload a file from a php form.It wont work on linux server. I want it to move it to a subdir '/uploads' from where the file is.</p>
  
  <p>I get the below error when executing the page by <code>echo</code> the <code>$_FILES["file_upload"]['error'];</code> to get the error number.</p>
  
  <p><strong>It returns :</strong></p>
  
  <pre><code>Upload failed with error code 6
  </code></pre>
  
  <p>Does anyone know what this error stands for?</p>
  
  <p><strong>Form Code :</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;form action="upload.php" method="post" enctype="multipart/form-data"&gt;
      Select File to upload:
      &lt;input type="file" name="file_upload" id="file_upload"&gt;
      &lt;input type="submit" value="Upload File" name="submit"&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>upload.php :</strong></p>
  
  <pre><code>&lt;?php
  
      if(isset($_POST['submit']))
      {
          if($_FILES['file_upload']['name'] != "" )
      {
              $target_dir = "uploads/";
              $target_file = $target_dir . basename($_FILES["file_upload"]["name"]);
              $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
              $uploadOk = 1;
      }
      else
      {
          die("No file specified!");
      }
  
      // Check if file already exists
      if (file_exists($target_file)) {
          echo "Sorry, file already exists.";
          $uploadOk = 0;
      }
  
      // Check file size
      if ($_FILES["file_upload"]["size"] &gt; 500000) {
          echo "Sorry, your file is too large.";
          $uploadOk = 0;
      }
  
      // Allow certain file formats
      if($imageFileType != "txt" &amp;&amp; $imageFileType != "xls" &amp;&amp; $imageFileType != "xlsx")
       {
          echo "Sorry, only TXT, XLS, XLSX files are allowed.";
          $uploadOk = 0;
      }
  
      if ($_FILES["file_upload"]['error'] !== UPLOAD_ERR_OK) {
         die("Upload failed with error code " . $_FILES['file_upload']['error']);
      }
      // Check if $uploadOk is set to 0 by an error
      if ($uploadOk == 0) {
          echo "Sorry, your file was not uploaded.";
      // if everything is ok, try to upload file
      } else {
          if (move_uploaded_file($_FILES["file_upload"]["tmp_name"], $target_file)) {
              echo "The file ". basename( $_FILES["file_upload"]["name"]). " has been uploaded.";
          } else {
              echo "Sorry, there was an error uploading your file.";
          }
      }
      }
      ?&gt;
  </code></pre>
  
  <p>I already search for this problem and find the solution <a href="https://stackoverflow.com/questions/8719244/move-uploaded-file-error-6-php">Here</a>. But not undestand properly.<br><br>
  I also given full permission <strong>777</strong> to <code>/uploads</code> folder.
  Any help will be greatly appreciated. Thanks</p>