What is the recommended method for saving an image from an external link to a specific directory on a server using PHP?
When saving an image from an external link to a specific directory on a server using PHP, you can use the `file_get_contents()` function to retrieve the image data from the URL, and then use the `file_put_contents()` function to save the image to the desired directory on the server. Make sure to validate the URL and handle any errors that may occur during the process.
$url = 'https://example.com/image.jpg';
$directory = '/path/to/directory/';
$filename = basename($url);
$imageData = file_get_contents($url);
if($imageData !== false) {
file_put_contents($directory . $filename, $imageData);
echo 'Image saved successfully.';
} else {
echo 'Failed to fetch image data.';
}