title: upload doc, docx, pdf files on server using php
body: <p>I wish to upload documents having extensions doc, docx and pdf on server. for this i used the following code but i am not able to upload the files</p>
  
  <pre><code>&lt;?php
  if($_POST['save'])
      {
  
          $target_dir = "reqdoc/";
          $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
          $uploadOk = 1;
          $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
          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($imageFileType != "doc" &amp;&amp; $imageFileType != "docx" &amp;&amp; $imageFileType != "pdf" ) 
              {
                  echo "Sorry, only doc, docx, pdf";
                  $uploadOk = 0;
              }
          if ($uploadOk == 0) 
              {
                  echo "Sorry, your file was not uploaded.";
              } 
          else 
              {
                  if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) 
                      {
                          echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
                      } 
                  else 
                      {
                          echo "Sorry, there was an error uploading your file.";
                      }
              }
      }
  ?&gt;
  
  &lt;p&gt;&amp;nbsp;&lt;/p&gt;
  &lt;form class="form-horizontal" role="form" action="&lt;?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?&gt;" method="POST"&gt;
      &lt;input type="file" name="fileToUpload" id="fileToUpload"&gt;
      &lt;button type="submit" value="submit" name="save"&gt;Save&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>i got the error saying </p>
  
  <pre><code>Sorry, file already exists.Sorry, only doc, docx, pdfSorry, your file was not uploaded.
  </code></pre>
  
  <p>can anyone please tell where the code went wrong</p>