title: php upload file condition not working
body: <p>i have a page where the the visitor can upload a file, but thats not required, so in my script i put a condition if the file input (i named it 'upload') is not set or empty don't upload anything, and the file name will be equal to 'file' already existed in db; else upload it.
  the problem is the condition is not working; even when i leave the input empty the upload script is executed; i know that because i get the messages that are declared in the script
  here is the coded and thank you</p>
  
  <pre><code>    //select exercice
  $ex_query = mysqli_query($link, " SELECT * FROM exercices WHERE ID = '".$exercice_ID."' ");
  $exercice = mysqli_fetch_assoc($ex_query);
  // --- update script if post
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
      if (isset($_FILES["upload"]) &amp;&amp; !empty($_FILES["upload"])){
          $target_dir = "docs/";
          $date_f_n = date("Y-m-d_h-i-sa");
          $file_n = basename( $_FILES["upload"]["name"]);
          $file_n = $date_f_n.$file_n;
          $target_file = $target_dir . $file_n;
          $uploadOk = 1;
          $FileType = pathinfo($target_file,PATHINFO_EXTENSION);
          // Check if  file is a actual image or fake image
              $check = filesize($_FILES["upload"]["tmp_name"]);
              if($check !== false) {
                  $uploadOk = 1;
              } else {
                  $filesizeer = "File is not an image.";
                  $uploadOk = 0;
              }
           // Check file size
          if ($_FILES["upload"]["size"] &gt; 5000000) {
              $filesizeer = "Sorry, your file is too large.";
              $uploadOk = 0;
          }
          // Check if $uploadOk is set to 0 by an error
          if ($uploadOk == 0) {
              $error = "Sorry, your file was not uploaded.";
          // if everything is ok, try to upload file
          } else {
               if (move_uploaded_file($_FILES["upload"]["tmp_name"], $target_file)) {
              $upsuccess= "The file ". $file_n. " has been uploaded.";
              } else {
                  $upfaled =  "Sorry, there was an error uploading your file.";
              }
          }//end else upload = 0
      }else{
          $file_n = $exercice['file'];
      }
  </code></pre>