发现电脑端下ZIP文件完美无错,用手机浏览器和第三方浏览器下载变成了乱码,苹果手机还会给ZIP下载文件变成html格式。
解决方案
网上找了很多种解决方法,有的说是编码没设置好,有的说函数错乱。最后测试,精准像素发现只是没在自定义函数方法的最后加“exit;”
1 2 3 4 5 6 7 8 9 10 11 | header('Content-Description: File Transfer');header('Content-Transfer-Encoding: binary');header('Cache-Control: public, must-revalidate, max-age=0');header('Pragma: public');header('X-Generator: mPDF ' . static::VERSION);header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');header('Content-Type: application/pdf');echo $this->buffer;exit;//加exit是为了解决有些手机下载pdf文件的后缀会变成(.html)的问题break; |
在结尾加上exit;后,下载文件页面不乱码了,而且苹果手机下载ZIP文件也不会变成html格式了,完美解决。
