When you load an image from an external source with file_get_contents
you can handle any errors like this:
$imgContent = @file_get_contents('https:\\www.external.url\image.jpg');
if ($imgContent === false) {
echo json_encode([
'success' => false,
'localUrl' => null,
'message' => 'Afbeelding kon niet worden opgehaald'
]);
exit;
}
}
Adding the @
surpresses the error message and the statement itself returns the content or just false
when not possible to get something.