title: php checking upload file if the name exist already
body: <pre><code>&lt;?php
  $target_dir = "uploads/";
  $target_file = $target_dir . basename($_FILES['fileToUpload']['name']);
  $uploadOk = 1;
  $FileType = pathinfo($target_file,PATHINFO_EXTENSION);
  
  // Check if file already exists
  if (file_exists($target_file)) {
  echo "Sorry, $target_file already exists.";
  $uploadOk = 0; 
  }
  
  //check file size
  if ($uploadFile_size &gt; 1) {
  echo nl2br("sorry, exceeded file size
  \r\n check your file size.
  \r\n Error Code: ");
  var_dump($_FILES['file']['error']); 
  $uploadOk = 0;
  }
  
  // check if there is error
  if ($uploadOk == 0) {
  echo nl2br("sorry, no files are uploaded
  \r\n check the file and try again
  \r\n Error Code: ");
  var_dump($_FILES['file']['error']); 
  
  // if no error
  } else { 
  if (move_uploaded_file($_FILES["uploadFile"]["tmp_name"], $target_dir)) {
      echo "your ". basename( $_FILES["uploadFile"]["name"]). " file is successfully uploaded.";
      echo nl2br("\r\n thank you.");
      echo nl2br("\r\n you may close the window.");       
  } 
  else {
      echo  nl2br("-file upload fail- \r\n Error Code: ");
      var_dump($_FILES['file']['error']); 
      echo nl2br("\r\n \r\n please, check your file one more time.");
  }
  }
  ?&gt;
  </code></pre>
  
  <p>Hi, the above is part of my php script and $target_file suppose to refer a file that is selected to be upload onto the server but it keep refers "uploads/" directory.</p>
  
  <p>Since $target_file is referring "uploads/" no matter which file i selected to upload, it keeps generating error that the file is already exist on the server.</p>
  
  <p>The script is copied exactly same from w3school webpage and I am using chrome browser to examine if the script works correctly.</p>
  
  <p>Can someone help me to fix this simple error?  My problem will most likely to be solved if the $target_file can be referred after file that is selected to be uploaded.</p>
  
  <p>Thank you.</p>