title: Rename and overwrite uploaded files
body: <p>I use the following code to upload images to Wordpress</p>
  
  <pre><code>function custom_upload_name($filename)
  {
    $info = pathinfo($filename);
  
   $item_id = $_POST['item_id'];    
    $filename  =  $item_id . '.jpg';
       return $filename;
   }
  
  add_filter('sanitize_file_name', 'custom_upload_name', 10);
  
  if ( ! function_exists( 'wp_handle_upload' ) ) require_once( ABSPATH . 'wp-admin/includes/file.php' );
   $item_id = $_POST['item_id'];
  $uploadedfile = $_FILES['file'];
    $image_name = $item_id;
  $upload_overrides = array( 'test_form' =&gt; false );
  $movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
  if ( $movefile ) {
      //file is uploaded successfully. do next steps here.
        echo $location_home .'/images/' .$image_name . '.jpg';  
  }
  </code></pre>
  
  <p>The renaming of the files works correctly. But I select the same image twice to upload everything is fine, but if I select a different image to upload, Wordpress automatically adds an number to the file:</p>
  
  <ul>
  <li>Result on first upload: 
  10000.jpg </li>
  <li>Result on second upload (same file, with same id):
  100001.jpg</li>
  <li>Result on third upload (same file, with same id):
  1000012.jpg</li>
  </ul>
  
  <p>How to let Wordpress automatically overwrite the files with the same id, without adding extra numbers to the file?</p>