lijuqwert
diergelicheng
2017-05-12 04:01
采纳率: 100%
浏览 846
已采纳

zend framework 下载 导出

我这里一个系统,用的是 zend frame 框架和sqlite数据库,本来没问题,后改成mysql数据库,问题其他正常,就是导出word,excel,以及下载都有问题了,导出的文件和下载的文件都不正常,打不开了
一下是导出word的代码:
/**
* 导出视频评论的word文档
*/
public function exportcomments1Action() {
$vid = $_GET['vid'];
require_once "PHPWord/PHPWord.php";
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
$PHPWord->addFontStyle('r1Style', array('color'=>'000000','bold'=>true, 'italic'=>false, 'size'=>12));
$PHPWord->addFontStyle('r2Style', array('color'=>'000000','bold'=>false, 'italic'=>false, 'size'=>11));

    $sql = "";
    $sql = "select * from videocomment  where vid='$vid' and is_active='1' order by time asc";
    $comments = $this->db->Execute($sql);

//    $comments = D('VideoComment') -> getCommentsByVid($vid);
    $sql = "";
    $sql = "select * from video_tmp where id='$vid'";
    $videoinfo = $this->db->getRow($sql);

 //   $videoinfo = D('Video') -> getVideoByVid($vid);
    $videoname = $videoinfo["title"];
  //  $videouid = $videoinfo['uid'];

   $sql = "";
   $videoowner="jkl";
 //   $videoowner = D('User') -> getDisplayName($videouid);
    $header = $section->createHeader();
    $header->addText('[专家视频点评汇总]',array('bold'=>false,'size'=>10,'underline'=>single),array('align'=>'right'));
    $section->addText('视频编号为'.$vid.'的专家点评汇总', 'r1Style');
    $section->addTextBreak(1);
 //   $section->addText('视频名称:'.$videoname.'   '.'上传人:'.$videoowner, 'r1Style');
   $section->addText('视频名称:'.$videoname, 'r1Style');
    $section->addTextBreak(1);
    $table = $section->addTable();
    $table->addRow();
 //   $table->addCell(5000)->addText("点评图片",'r2Style');
    $table->addCell(5000)->addText("专家点评",'r2Style');

    foreach ($comments as &$c) {
        $table->addRow();
    //    $c['dname'] ="二的";
     //   $c['dname'] = D('User') -> getDisplayName($c['uid']);
      //  $table->addCell(5000)->addImage($c['thumb_path'],array('width'=>250, 'height'=>250));
        $comment_content = "专家—的点评:".$c['content'];
        $table->addCell(5000)->addText($comment_content,'r2Style');

    }


    // Save File
    $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
    $filename = '视频评论导出'.$vid.'.docx';//要保存的文件名
    $filename=iconv("utf-8","gb2312",$filename);
    $filepath = sys_get_temp_dir().'/'.$filename;   //要下载的文件地址

    $objWriter->save($filepath);
    ob_end_clean();
    header("Content-Type: application/force-download");
    header("Content-Disposition: attachment; filename=".$filename);
    readfile($filepath);

  exit();
}

我把上面代码中和数据库有关的代码都去掉,只随意写几个字母数字进去,导出来也不正常,下载也是一样。估计是zend framework 哪里要设置下

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • lijuqwert
    diergelicheng 2017-05-12 04:03
    已采纳

    问题解决了C币再加几倍都可以

    点赞 评论

相关推荐