繁体   English   中英

如何在yii中下载xml文件

[英]How to download xml file in yii

我想在yii中创建和下载xml文件,所以我已经编写了创建xml文件的代码,它工作正常,但是下载xml文件时却出现错误
我尝试过代码

//xml structure
$xmldata = '<?xml version="1.0" encoding="utf-8"?>';
$xmldata .= '<MemberBill>';
foreach ($model as $model)
{
    $xmldata .= '<Bill>';
    $xmldata .= '<BillNo>'.$model->bill_no.'</BillNo>';
    $xmldata .= '</Bill>';
}
$xmldata .= '</MemberBill>';

if(file_put_contents('memberBill.xml',$xmldata)) // this code is working fine xml get created
{
    //echo "file created";exit;
    header('Content-type: text/xml');   // i am getting error on this line
    //Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\yii\framework\web\CController.php:793)

    header('Content-Disposition: Attachment; filename="memberBill.xml"');
    // File to download
    readfile('memberBill.xml');        // i am not able to download the same file
}

D:\\xampp\\htdocs\\yii\\framework\\web\\CController.php:793代码已经开始输出-它是render方法。 我认为您在此代码之前已经渲染了一些东西!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM