PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 8, 2022

[FIXED] How to download xml file in yii

 March 08, 2022     header, php, readfile, xml, yii     No comments   

Issue

I want to create and download xml file in yii so i have write code to create xml file and it's working fine but it is giving error while downloading xml file
i have tried code

//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
}

Solution

In D:\xampp\htdocs\yii\framework\web\CController.php:793 code already start outputting - it's method render. I think you has already rendered something before this code!



Answered By - CreatoR
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing