Save Image from URL to S3

if(!function_exists('save_to_s3')){
	function save_to_s3($user_id, $url, $host=null){
		if($host != false){
			$opts = array(
			    'http'=>array(
			        'method'=>"GET",
			        'header'=>"Host: " . $host . "\r\n" .
			            "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36"
			    )
			);
			$context = stream_context_create($opts);

			$image = file_get_contents($url, false, $context);
		}else{
			$image = file_get_contents($url);
		}
        //logg($dest);

		//連domain後的路徑一併存下來
		$parse = parse_url($url);
        $dest = $user_id . $parse['path'];
        //$file_name = basename($url);
        
        Storage::disk('s3')->put($dest, $image, 'public');

        $url = config('wikirex.s3_url');
        $url .= '/' . $dest;
        return $url;
	}
}