2016-07-20 14:17:07 11480次浏览 3条回答 4 悬赏 10 金钱
$res = \YII::$app->response;
$res->sendFile('./1111.txt');
//指定某个文件发给浏览器进行下载

这么写可以吗,有没有好的下载,分享下

  • 回答于 2016-07-20 14:35 举报

    自己跑下就有结论了。

  • 回答于 2016-07-20 14:37 举报

    直接丢个链接出来也是可以的,也可以把信息多补充点方便客户端识别。

    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename='.$file_name);
    header('Cache-Control: max-age=0');
    $objWriter->save('php://output');
    
    2 条回复
    回复于 2016-12-14 17:18 回复

    $objWriter 是什么对象?

    回复于 2016-12-14 17:30 回复

    这个是phpexcel里的一段代码

    觉得很赞
  • 回答于 2017-07-20 17:01 举报
    public function actionSend()
    {
        $wrstr=htmlspecialchars_decode(file_get_contents('public/1.txt'));
        $outfile=time().'.'.'txt';
        header('Content-type: application/octet-stream; charset=utf8');
        Header("Accept-Ranges: bytes");
        header('Content-Disposition: attachment; filename='.$outfile);
        echo $wrstr;
        exit();
    }
    
    觉得很赞
您需要登录后才可以回答。登录 | 立即注册
37702
等待激活

37702

注册时间:2016-10-31
最后登录:1970-01-01
在线时长:0小时0分
  • 粉丝1
  • 金钱155
  • 威望20
  • 积分355

热门问题