title: PHP Upload move_uploaded_file not working
body: <p>I am trying to upload a file, and have it so that duplicate file names will be appended with _0, _1, _2 etc. When a duplicate file is entered I get this error:</p>
  
  <pre><code>Warning: move_uploaded_file(../data/uploads/../data/uploads/Penguins_0.jpg): failed to open stream: No such file or directory in D:\xampp\htdocs\staff\upload_form.php on line 29
  
  Warning: move_uploaded_file(): Unable to move 'D:\xampp\tmp\php7150.tmp' to '../data/uploads/../data/uploads/Penguins_0.jpg' in D:\xampp\htdocs\staff\upload_form.php on line 29
  Upload failed: Could not move uploaded file. [../data/uploads/Penguins_0.jpg]
  </code></pre>
  
  <p>Can Anyone please help?!</p>
  
  <pre><code>$id = "img_" . $_POST['eqId'] . "_" . $_POST['imgId'];
          $file = $_FILES[$id];
          $allowedExts = array("gif", "jpeg", "jpg", "png");
          $temp = explode(".", $file["name"]);
          $extension = strtolower(end($temp));
          $dir = "../data/uploads/";
          if(($file["type"] == "image/gif")
          || ($file["type"] == "image/jpeg")
          || ($file["type"] == "image/jpg")
          || ($file["type"] == "image/pjpeg")
          || ($file["type"] == "image/x-png")
          || ($file["type"] == "image/png")
          &amp;&amp; in_array($extension, $allowedExts)){
              if ($file["error"] &gt; 0){
                  echo "There was an error uploading the file. [Code: " . $file["error"] . "]";
              }else{
                  $fileName = $file['name'];
                  if (file_exists($dir . $file["name"])){
                      $appendCount = 0;
                      while(file_exists($dir . $temp[0] . "_" . $appendCount . "." . $extension)){
                          $appendCount++;
                      }
                      $fileName = ($dir . $temp[0] . "_" . $appendCount . "." . $extension);
                  }
  
                  if(move_uploaded_file($file["tmp_name"], $dir . $fileName )){
                      echo "success:" . $file["tmp_name"];
                  }else{
                      echo "Upload failed: Could not move uploaded file. [" . $fileName . "]";
                  }
  
              }
          }else{
              echo "Invalid file type '" . $extension . "'";
          }
  </code></pre>