php下载文件实例

//excel模板下载
public function excelDownload(){
    $excelPath = APPLICATION_ROOT . '/document/';
    $fileName  = "邮件玩家奖励信息表";
    $file_name = iconv("utf-8", "gb2312", $fileName);
    $file_path = $excelPath . $fileName . '.xlsx';
    $fp        = fopen($file_path, "r");
    $file_size = filesize($file_path);
    //下载文件需要用到的头
    Header("Content-type: application/octet-stream");
    Header("Accept-Ranges: bytes");
    Header("Accept-Length:" . $file_size);
    Header("Content-Disposition: attachment; filename=" . $file_name . '.xlsx');
    readfile($file_path);
    fclose($fp);
}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页