I\'m using forced download to download mostly zips and mp3s on site i did (http://pr1pad.kissyour.net) - to track downloads in google analytics, in database and to hide real
There's one thing I find weird: You are calling ob_end_flush() at the start of the function. This actually cleans the output buffer, but it also outputs everything to the client first (I assume including Content-Headers set by CodeIgniter). Change the call to ob_end_clean(), it clears the buffer and discards it. This will give you a clean start for generating your own headers.
Another tip:
Instead of reading the file as a stream and passing it on block-wise, you could give this function a try:
// ...
if (file_exists("dir-with-files/$filename")) {
readfile($file);
}
This takes care of nearly everything.