在使用php 的readfile函数 下载服务器的文件时,发现下载的文件总是不完整,打不开。
最后找到解决方法:只需在readfile函数之前调用这两个函数:
ob_clean(); #清空输出缓冲区
flush(); #刷新输出缓冲
示例代码如下:
header("Content-Transfer-Encoding: binary");
header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
header("Content-Disposition: attachment; filename=".basename($full_path));
#RS 2016-6-23 解决文件下载不完整
ob_clean();
flush();
readfile($full_path);
参考链接:
ob_clean() 函数介绍:http://php.net/manual/zh/function.ob-clean.php
flush() 函数介绍:http://php.net/manual/zh/function.flush.php
php手册:http://php.net/docs.php