Testing - PHP Download a file

Using file_get_contents and file_put_contents

<?php
$url = 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png';
 
// Download the file using file_get_contents.
$downloadedFileContents = file_get_contents($url);
 
// Check to see if file_get_contents failed.
if($downloadedFileContents === false){
    throw new Exception('Failed to download file at: ' . $url);
}
 
// The path and filename that you want to save the file to.
$fileName = 'logo.png';
 
// Save the data using file_put_contents.
$save = file_put_contents($fileName, $downloadedFileContents);
 
// Check to see if it failed to save or not.
if($save === false){
    throw new Exception('Failed to save file to: ' , $fileName);
}
?>