What is the best practice for displaying images from an external server in PHP?

When displaying images from an external server in PHP, it is best practice to download the image from the external server to your server and then display it. This helps to prevent hotlinking and ensures better control over the image display.

<?php

$remoteImage = 'https://example.com/image.jpg';
$localImage = 'local_image.jpg';

file_put_contents($localImage, file_get_contents($remoteImage));

echo '<img src="' . $localImage . '" alt="Image">';
?>