What is the potential issue with using file_get_contents to download a file larger than 5mb in PHP?

Using file_get_contents to download a file larger than 5mb in PHP can potentially lead to memory exhaustion, as the entire file is loaded into memory at once. To solve this issue, you can use the fopen function with the 'rb' flag to read the file in chunks and write it to the output stream incrementally.

$url = 'http://example.com/largefile.zip';
$handle = fopen($url, 'rb');
if ($handle) {
    while (!feof($handle)) {
        echo fread($handle, 8192);
    }
    fclose($handle);
}