PHP提供excel下载接口

Posted xuweiqiang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP提供excel下载接口相关的知识,希望对你有一定的参考价值。

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;

 

以上是关于PHP提供excel下载接口的主要内容,如果未能解决你的问题,请参考以下文章