Drupal获取保存外部图片文件的方法

论坛: 
function get_external_image($url) { 
    $external_image = file_get_contents($url);
    $parsed_url = parse_url($url);
    $name_dest = rand(1000,9999)."_". basename($parsed_url["path"]);
    $file = file_save_data($external_image, 'public://'.$name_dest , FILE_EXISTS_REPLACE);
    if (is_object($file) && file_exists($file->uri)) {
        $file->status = 1;
        $file = file_save($file);
        drupal_write_record('file_usage', $file);
        return (array) $file;
    }
    return null;
}

get_external_image("http://www.dsjz.cn/static/images/search_logo.png")

来自于 猎人分享