Have you tried adding "https:" to the from of the URL to see if it's related to a missing scheme?
Aug 16, 2019
5
Level 2
Save image from remote URL
Hi guys
I'm trying to extract an image from an API.
With the variable $game->cover->url I get //images.igdb.com/igdb/image/upload/t_thumb/csbqnva4b4nzdjgkbe8c.jpg, I would like this image in /upload /cover but every tenativo I do I fail him.
This is my code:
$cover = file_get_contents($game->cover->url);
$filename = rand().'-.'.$cover;
Image::make($cover)->save(public_path('/upload/cover' . $filename));
$platform->immagine = '/upload/cover/' . $name_cover;
dd($platform);
But I get the error LOG.info: [INVALID UTF-8 DATA]
I also tried with:
$cover = file_get_contents($game->cover->url);
$name_cover = substr($cover, strrpos($cover, '/upload/cover/') + 1);
Storage::put($name_cover, $cover);
$platform->immagine = '/upload/cover/' . $name_cover;
dd($platform);
But with this new code I get the error:
LOG.info: file_get_contents(//images.igdb.com/igdb/image/upload/t_thumb/csbqnva4b4nzdjgkbe8c.jpg): failed to open stream: No such file or directory
How do I save the image of the URL in my server?
Please or to participate in this conversation.