title: PHP file upload check - it is possible before sending the input via POST?
body: <p>I have a very basic code to upload form:</p>
  
  <pre><code>echo "&lt;form action='upload.php' method='post' enctype='multipart/form-data'&gt;";
  echo "Select upload:   ";
  echo "&lt;input type='file' name='fileToUpload' id='fileToUpload'&gt;";
  echo "&lt;input type='submit' value='Upload file' name='submit'&gt;";
  echo "&lt;/form&gt;";
  </code></pre>
  
  <p>Ok, now I want to check the input if the user has selected a file or not, but before sending the input filename via POST to another PHP file (upload.php)</p>
  
  <p>I know that checking if no file has been selected can be done something like this:</p>
  
  <pre><code>if(!isset($_FILES['fileToUpload']) || $_FILES['fileToUpload']['error'] == UPLOAD_ERR_NO_FILE) {
      echo "Error no file selected"; 
  } else {
      echo "ok";
  }
  </code></pre>
  
  <p>I know that somehow I need the check the input here in this file:</p>
  
  <pre><code>echo '&lt;form action="'.htmlspecialchars($_SERVER["PHP_SELF"]).'" method="post"&gt;';
  </code></pre>
  
  <p>But how can mix these together ? I want to pass the filename to another php file, when a file is selected.</p>
  
  <p>Thank you.</p>