Get not the full path

You might want to use the media_media_sideload_image() function. This function will fetch an image from a URL and upload it for you. Take a look into this custom function:

function upload_image_from_url($image_url, $post_id, $title) {
    $img_name = basename ($image_url);
    global $wpdb;
    $query = "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value="$img_name"";
    $id = $wpdb->get_var($query);
    if (is_numeric($id)) {
        return $id;
    } else {
        $attachment_src = media_sideload_image( $image_url, $post_id, $title,'src' );
        $query = "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value="$img_name"";
        $id = $wpdb->get_var($query);
        return $id;
    }
}

What the above function does, is to search the database to see if the image is already uploaded. If not, it will upload the image into the library and return it’s ID, which then can be used later by wp_get_attachment_url() to get the URL.

You can tweak this function not to depend on $post_id or $title ( by detaching the attachment from the post after it’s uploaded) to get what you demand.

This is safe, and guaranteed to work (if you don’t consider the extraordinary situations).