plugin development – wordpress upload file programmatically

I am trying to programmatically add multiple images to media library, I uploaded the images to wp-content/uploads/dits.

I am working with this code but this code is not working, can you tell me what is wrong with me

Display Error

Fatal error: Uncaught Error: Call to undefined function WP_Filesystem() in /var/www/projects/

  global $wp_filesystem;
  WP_Filesystem();

  $content_directory = $wp_filesystem->wp_content_dir() . 'uploads/';
  $wp_filesystem->mkdir( $content_directory . 'dits' );
  $target_dir_location = $content_directory . 'dits/';

 if(isset($_POST('submit'))){

   $_SESSION('message') = $message;

   $name_file = $_FILES('fileToUpload')('name');
   $tmp_name = $_FILES('fileToUpload')('tmp_name');

   if( move_uploaded_file( $tmp_name, $target_dir_location.$name_file ) ) {
      echo "File was successfully uploaded";
   } else {
      echo "The file was not uploaded";
   }

   }

<form action="<?php echo site_url('370-2/?step=contact'); ?>" method="post" enctype="multipart/form-data">
                <textarea name="message" rows="20" cols="120" placeholder="Describe the project" required="required"> <?php  echo $prj_description; ?> </textarea>
                <div class="container drag_con">
                  <div class="row">
                    <div class="col-md-12">
                          <!--<input type="file" name="fileToUpload" id="fileToUpload" class="dropzone">-->
                          <input type="file" accept=".xlsx,.xls,image/*,.doc,audio/*,.docx,video/*,.ppt,.pptx,.txt,.pdf" name="fileToUpload" id="fileToUpload" multiple>

                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="row">
                    <div class="col-12">
                      <div class="next-button-box text-center mt-5">
                         <button  type="submit" name="submit" class="primary-button" id="next">NEXT</button>
                        
                      </div>
                    </div>
                </div>
 </form>