force_download() used with file_get_contents() result in corrupted files
When trying to serve .doc or .docx files (applies to other office documents as well) with the above method, the files downloaded cannot be opened. Error says it's corrupted.
Added added ob_clean(); and flush(); right before the exit($data); call at the end of the force_download() function and it worked fine.
Have not confirmed if this is compatible with other filetypes yet but it worked fine with .pdf as well.
Actually, did a few tests. Works fine with .txt too. Haven't tried images. Also thinking that having ob_clean(); right before the header() output is probably a better idea.
Could you submit a pull request with the suggested changes?
Yep. Just submitted.
Hi There, ob_clean(); followed by flush(); inserted before exit($data); helped me, xlsx, jpg, png, txt,...worked. Thanks.