I am trying to create a form with the posibility to upload a file but it seems that I cannot make this input a none required one. In each time I try to verify that there is no uploaded file the code keeps on getting inside the condition.

```
 if (isset($_FILES['fileToUpload']) && !empty($_FILES['fileToUpload']['name'])){
    // Set files location
    $target_dir = "media/";
    $total = count($_FILES['fileToUpload']['name']);
    $uploadOk = 1;
    // Check if there is files to be uploaded.
      if($total != 0) {
           //$uploadOk = 1;
           for($i=0; $i<$total; $i++) {

           $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"][$i]);
           $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
           $namee =$_FILES["fileToUpload"]["name"][$i];
           // Check if file already exists
           if (file_exists($target_file)) {
               header('location: new_report.php?upload=fileexist');
               $uploadOk = 0;
           }
           // Check file size
           if ($_FILES["fileToUpload"]["size"][$i] > 500000) {
               header('location: new_report.php?upload=toobig');
           }
           // Allow certain file formats
           if($imageFileType != "png" && $imageFileType != "jpg"  ) {
               var_dump($_FILES['fileToUpload']['name']);
              // exit;
             header('location: new_report.php?upload=filenotallowed');
               $uploadOk = 0;
           }
           // Check if $uploadOk is set to 0 by an error
           if ($uploadOk == 0) {
               echo "Sorry, your file was not uploaded.";
           // if everything is ok, try to upload file
           } else {
               if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"][$i], $target_file)) {
               Do something..
               } else {
                   header('location: new_report.php?upload=error');
               }
           }
           }

      }
    }

```

Even if I don't upload a file, I keeps on going inside the do something part of the code.

The html code is :

```
<form action="submit_report.php" method="POST" enctype="multipart/form-data">
    <input class="btn btn-primary" name="fileToUpload[]" type="file" multiple="multiple" id="fileToUpload">
</form>

```

Is meant to be for a multiple choice file