title: Cannot upload my attachment file to wordpress upload folder and add the data to custom database table together
body: <p>I am willing to upload the image attachment file to wordpress content upload folder and as well as adding data to the custom table of wordpress. Both of the function work fine separately but cant run together in a class function. Please help me on this. It is a plugin activated for custom post that contain custom form.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> public function __construct() {
          $mainPageHook = add_action('init', array($this, 'profilePost'));  
          add_action("admin_init",array($this, 'profileMeta'));
          add_action("load-{$mainPageHook}", array($this, 'mainPageAssets'));
          add_action("save_post", array($this, 'save_custom_fields') );
          add_action("save_post", array($this, 'handle_upload') );
          add_action('enqueue_block_editor_assets', array($this, 'adminAssets'));
      } </code></pre>
  </div>
  </div>
  </p>
  <p>My form function</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public function profileMetaPost(){
          ?&gt;
          &lt;div class="container"&gt;
              &lt;h1&gt;User Profiles Registration&lt;/h1&gt;
              &lt;form action="" method="post" enctype="multipart/form-data"&gt;
                  &lt;div class="row"&gt;
                      &lt;div class="col-25"&gt;
                          &lt;label for="fname"&gt;First Name&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div class="col-75"&gt;
                          &lt;input type="text" id="fname" name="first_name"  placeholder="Your name.."&gt;
                      &lt;/div&gt;
                      &lt;div class="col-25"&gt;
                          &lt;label for="subject"&gt;Short Description&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div class="col-75"&gt;
                          &lt;textarea id="short_description" name="short_description" placeholder="Write short Description about your role" style="height:200px"&gt;&lt;/textarea&gt;
                      &lt;/div&gt;
                      &lt;div class="col-25"&gt;
                          &lt;label for="position"&gt;Position&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div class="col-75"&gt;
                          &lt;input type="text" id="fname" name="position" placeholder="Your Position"&gt;
                      &lt;/div&gt;
                      &lt;div class="col-25"&gt;
                          &lt;label for="social-media-link"&gt;Social Media Link&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div class="col-75"&gt;
                          &lt;input type="text" id="fname" name="social-media-link" placeholder="Your name.."&gt;
                      &lt;/div&gt;
                      &lt;div class="col-25"&gt;
                          &lt;label for="image"&gt;Upload Your Image&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div class="col-75"&gt;
                          &lt;input type="file" id="lname" name="image" placeholder="Your last name.."&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row"&gt;
                      &lt;input type="submit" value="Submit"&gt;
                  &lt;/div&gt;
              &lt;/form&gt;
           &lt;/div&gt;
          &lt;?php }</code></pre>
  </div>
  </div>
  </p>
  <p>handle upload function:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public function handle_upload($post_id){
          if ( ! function_exists( 'wp_handle_upload' ) ) {
              require_once( ABSPATH . 'wp-admin/includes/file.php' );
          }
          
          $uploadedfile = $_FILES['image'];
          
          $upload_overrides = array( 'test_form' =&gt; false );
          
          $movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
          
          if ( $movefile &amp;&amp; ! isset( $movefile['error'] ) ) {
              echo "File is valid, and was successfully uploaded.\n";
              var_dump( $movefile );
          } else {
              /**
               * Error generated by _wp_handle_upload()
               * @see _wp_handle_upload() in wp-admin/includes/file.php
               */
              echo $movefile['error'];
          }
          echo 'word';
      }</code></pre>
  </div>
  </div>
  </p>
  <p>My database saving function</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public function save_custom_fields($post_id){
          $name = $_POST['first_name'];
          $short_description = $_POST['short_description'];
          $position = $_POST['position'];
          $image = $_POST['image'];
  
          
          global $wpdb;
          $wpdb -&gt; insert(
              $wpdb -&gt; prefix . 'profile_info',
              [
                  'first_name' =&gt; $name,
                  'short_description' =&gt; $short_description,
                  'position' =&gt; $position,
                  'image' =&gt; $image,
  
              ]
          );
      }</code></pre>
  </div>
  </div>
  </p>