How to upload multiple forms

I have the following code and would like to give the user a chance to upload multiple files. I can manage to get the files to be uploaded, which is a good thing but my page just keep looping through and I get a undefined offset error, what does that mean?

 for($x=0; $x<($_FILES['file']['name']); $x++) {
      
  

  $file = $_FILES['file'];
  $fileName = $_FILES['file']['name'][$x];
  $fileTmpName= $_FILES['file']['tmp_name'][$x];
  $fileSize = $_FILES['file']['size'][$x];
  $fileError = $_FILES['file']['error'][$x];
  $fileType = $_FILES['file']['type'][$x];
 
  $fileExt = explode('.', $fileName);
  $fileActualExt = strtolower(end($fileExt));
  

  $allowed = array('jpg', 'jpeg', 'png', 'pdf');

  if (!in_array($fileActualExt, $allowed)) {
      echo "<meta http-equiv='refresh' content='0;url=index.php?upload_form=error'>";
      exit();
  } else {
      if ($fileError === 1) {
          echo "<meta http-equiv='refresh' content='0;url=index.php?upload_form=errorwithform'>";
        exit();
      } else {
         if ($fileSize > 5000000000) {
            echo "<meta http-equiv='refresh' content='0;url=index.php?upload_form=filesizeerror'>";
        exit();
         } else {
                  $fileNameNew = "profile".$id.".".$fileActualExt;
                  $fileDestination = 'uploads/'.$fileNameNew;
                   move_uploaded_file($fileTmpName, $fileDestination);
             
            
            
            $sql2 = "INSERT INTO pictures (name, pictures) VALUES (?,?);";
            
            $stmt = mysqli_stmt_init($conn);
                        if(!mysqli_stmt_prepare($stmt, $sql2)) {
                           echo "SQL error";
                        } else {
                          mysqli_stmt_bind_param($stmt, "ss", $clinic_name, $fileDestination);
                          mysqli_stmt_execute($stmt);
                        }              
            
           echo "<meta http-equiv='refresh' content='0;url=index.php?medical_review_process=success'>"; 
                               
                                
           
         }
      }
  }
}
}
}
}                         

                      

                       
}

I also keep getting an extension error even though I uploaded the correct extension…

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.