header 信息填好就行, 直接 echo 会在浏览器输出乱码
- <?PHP
- set_time_limit(0);
- ini_set('memory_limit', '-1');
- try{
- // 上传时间
- $filePath = 'worl.xlsx';
- header('Content-Description: attachment; File Transfer');
- header('Content-Disposition: attachment; filename=test.xlsx');
- header('Content-Transfer-Encoding: binary');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Expires: 0');
- // 如果文件非常大的情况可以使用 ob 缓冲区 - 先加载到缓冲区再输出
- echo file_get_contents($filePath);
- } catch (\Exception $e) {
- echo 0;
- }
来源: http://www.bubuko.com/infodetail-3106849.html