$post_id = 100; // 投稿ID
$filename = '/tmp/sample.jpg';
$filetype = wp_check_filetype( basename( $filename ), null );
$wp_upload_dir = wp_upload_dir();
$attachment = array(
 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ),
 'post_mime_type' => $filetype['type'],
 'post_title' => preg_replace( '/.[^.]+$/', '', basename( $filename ) ),
 'post_content' => '',
 'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $filename, $post_id );
require_once( ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );

これを実行したあと、管理画面のライブラリを見ると、URLに下記のように書かれています。
このURLが/tmpが含まれたフルパスになっているためだと思うのですが、どこが問題なのでしょうか?

ttp://example.com/wp-content/uploads//tmp/sample.jpg