Automatically Rename Files On Upload

Modify your functions.php in the theme:

function sha1_upload_file( $file_array ) {
    $file_array['name'] = sha1( file_get_contents( $file_array['tmp_name'] ) ) . '.' . pathinfo( $file_array['name'], PATHINFO_EXTENSION );
    return $file_array;
}

add_filter( 'wp_handle_upload_prefilter', 'sha1_upload_file', 10, 1 );

The point is wp_handle_upload_prefilter hook.

I have tried sanitize_file_name hook. But the hook only returned filename, not file content.

References: