CodeIgniter icon indicating copy to clipboard operation
CodeIgniter copied to clipboard

force_download() used with file_get_contents() result in corrupted files

Open samxli opened this issue 14 years ago • 4 comments

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.

samxli avatar Apr 23 '12 13:04 samxli

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.

samxli avatar Apr 23 '12 13:04 samxli

Could you submit a pull request with the suggested changes?

narfbg avatar Apr 23 '12 13:04 narfbg

Yep. Just submitted.

samxli avatar Apr 23 '12 15:04 samxli

Hi There, ob_clean(); followed by flush(); inserted before exit($data); helped me, xlsx, jpg, png, txt,...worked. Thanks.

sspaky avatar Oct 10 '14 06:10 sspaky