wp_handle_upload to overwrite existing file with same name?

I need to force wp_handle_upload to overwrite a file with the same name as the one being uploaded:
this is my current code:

if ( ! function_exists( 'wp_handle_upload' ) ) require_once( ABSPATH . 'wp-admin/includes/file.php' );
            $uploadedfile = $_FILES['myfile'];
            $new_filename="amine";
            $upload_overrides = array( 'test_form' => false );
            $movefile = wp_handle_upload( $uploadedfile, $upload_overrides );

Related posts

Leave a Reply

2 comments

  1. i think you can force overwrite the existing file with the same name by adding custom wp_unique_filename callback, pass it on $upload_overrides args like this

    ...
    $upload_overrides = array( 'test_form' => false, , 'unique_filename_callback' => 'your_custom_callback' );
    ...
    
    function your_custom_callback($dir, $name, $ext){
        return $name;
    }