PHP basic upload file script
<p>This is my first time attempting to upload a file via PHP.</p>

<p>Here is my HTML:</p>

<pre><code>&lt;form role="form" action="api/upload.php" id="uploadForm" method="post" enctype="multipart/form-data"&gt;
   &lt;input id="fileToUpload" name="fileToUpload" type="file" class="file" /&gt;
   &lt;button type="submit" name="submit" id="submit"&gt;Upload&lt;/button&gt;
&lt;/form&gt;
</code></pre>

<p>Now here is the PHP script in reference "api/upload.php":</p>

<pre><code>&lt;?php
$target_dir = "files\\";

if(isset($_POST["submit"])) {
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
}

if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}

if ($_FILES["fileToUpload"]["size"] &gt; 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}

if ($uploadOk == 0) {
echo $uploadOk . "Sorry, your file was not uploaded.";
} else {
  if (move_uploaded_file($_FILES["fileToUpload"]["name"], $target_file)) {
   echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  } else{
     echo "Sorry, there was an error uploading your file.";
  }
} 
?&gt;
</code></pre>

<p>This may be a logic error.  I'm not sure.  Regardless, I keep getting the message:</p>

<blockquote>
  <p>Sorry, there was an error uploading your file</p>
</blockquote>

<p>When I echo out $uploadOk, it remains as 1. How can I find my error?</p>