title: Wordpress - wp_handle_upload - how to get the file name/directory of the uploaded file?
body: <p>I am working on a WordPress website which allows users to upload files upon registration. I got the upload and registration portion working. Below is the code that handles the upload once the user clicks the register button:</p>
  
  <pre><code>function text_domain_woo_save_reg_form_fields($customer_id) {
      //First name field
      if (isset($_POST['billing_first_name'])) {
          update_user_meta($customer_id, 'first_name', sanitize_text_field($_POST['billing_first_name']));
          update_user_meta($customer_id, 'billing_first_name', sanitize_text_field($_POST['billing_first_name']));
      }
      //Last name field
      if (isset($_POST['billing_last_name'])) {
          update_user_meta($customer_id, 'last_name', sanitize_text_field($_POST['billing_last_name']));
          update_user_meta($customer_id, 'billing_last_name', sanitize_text_field($_POST['billing_last_name']));
      }
              // $target_path = "c:/"; 
          // $target_path = $target_path.basename( $_FILES['image_verification']['name']); 
          // echo " &lt;script&gt;console.log('it hit!!'); &lt;/script&gt;";
          // echo " &lt;script&gt;console.log('image upload - success! " . $target_path . "' ); &lt;/script&gt;";
          // if(move_uploaded_file($_FILES['image_verification']['tmp_name'], $target_path)) { 
              // echo "File uploaded successfully!";
              // echo " &lt;script&gt;console.log('image upload - success!'); &lt;/script&gt;";
              // echo " &lt;script&gt;console.log('image upload - success! " . $target_path . "' ); &lt;/script&gt;";
          // } else { 
              // echo "Sorry, file not uploaded, please try again!"; 
              // echo " &lt;script&gt;console.log('image upload - fail!'); &lt;/script&gt;";
              // echo " &lt;script&gt;console.log('image upload - success! " . $target_path . "' ); &lt;/script&gt;";
          // } 
  
      if ( ! function_exists( 'wp_handle_upload' ) ) {
          require_once( ABSPATH . 'wp-admin/includes/file.php' );
      }
  
      $uploadedfile = $_FILES['image_verification'];
      $movefile = wp_handle_upload($uploadedfile, array('test_form' =&gt; false));
  
      if ($movefile &amp;&amp; !isset($movefile['error'])) {
          var_dump($movefile);
      } else {
          echo $movefile['error'];
      }
  
  }
  </code></pre>
  
  <p>The wp_handle_upload moves the file the user uploads into the C:\wamp64\www\wordpress\wp-content\uploads\2018\07\imgname.png directory.</p>
  
  <p>now my concern here is:</p>
  
  <p>if 2 users register and they both upload the file imgname.png, it will rename the second "imgname.png" to "imgname-1.png". This is perfectly fine but I am trying to also store a reference to these images in the database, how would I be able to know if the image got renamed or not?</p>
  
  <p>Do you guys have any suggestions for this?</p>
  
  <p>Example: UserA signing up uploads a file called "test.png", i want to create a record in the db like this:</p>
  
  <pre><code>|UserA|localhost\wordpress\wp-content\uploads\2018\07\test.png.|
  </code></pre>
  
  <p>Now UserB signing up uploads a file called "test.png", his file will be renamed "test-1.png". Therefore I would need to create a record in the DB for him as the following:</p>
  
  <pre><code>|UserA|localhost\wordpress\wp-content\uploads\2018\07\test-1.png.|
  </code></pre>
  
  <p>How would I get the directory/image name of the file if the change to "test 1.png" happened after it was uploaded?</p>
  
  <p>Any suggestions?</p>