What is the purpose of archiving files from an external website using PHP?

Archiving files from an external website using PHP allows you to create a local copy of the files for offline access or backup purposes. This can be useful for ensuring that important files are always available even if the original website goes down or if you need to access the files without an internet connection.

<?php
$url = 'https://www.example.com/file-to-archive.pdf';
$localFilePath = 'archive/file-to-archive.pdf';

// Download the file from the external website
file_put_contents($localFilePath, file_get_contents($url));

echo 'File archived successfully!';
?>