Are there any potential issues with using fread() function in PHP for file downloads?

Using the fread() function in PHP for file downloads can potentially lead to memory exhaustion issues if the file being read is too large. To solve this issue, you can read the file in smaller chunks using a loop until the entire file is read.

$filename = 'example.txt';
$chunkSize = 1024; // Read 1KB at a time

$handle = fopen($filename, 'rb');
if ($handle) {
    while (!feof($handle)) {
        echo fread($handle, $chunkSize);
    }
    fclose($handle);
}