完善了文件输出类,修改了csv格式和乱码的问题
This commit is contained in:
parent
5848e2206d
commit
e4ef7119fb
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
use Helper\View as view;
|
use Helper\View as view;
|
||||||
use Files\Files;
|
use Files\Files;
|
||||||
|
use Files\Output;
|
||||||
use Files\Listener\FileListener;
|
use Files\Listener\FileListener;
|
||||||
|
|
||||||
class Admin_DownController extends Zend_Controller_Action
|
class Admin_DownController extends Zend_Controller_Action
|
||||||
|
@ -753,27 +754,13 @@ class Admin_DownController extends Zend_Controller_Action
|
||||||
$this->_helper->viewRenderer->setNoRender();
|
$this->_helper->viewRenderer->setNoRender();
|
||||||
$sql="select * from offlineapp where ts_approved is not null and pdflink is not null order by ts_created desc";
|
$sql="select * from offlineapp where ts_approved is not null and pdflink is not null order by ts_created desc";
|
||||||
$rows=$this->db->fetchAll($sql);
|
$rows=$this->db->fetchAll($sql);
|
||||||
|
|
||||||
foreach($rows as $row){
|
foreach($rows as $row){
|
||||||
$content.='"'.$row['username'].'","'.$row['unit'].'","'.$row['phone'].'","'.$row['address'].'","'.$row['postcoe'].'","'.str_replace("\"","'",$row['project']).'","'.str_replace("\"","'",$row['datalist']).'","'.$row['email'].'",'.$row['ts_created']."\n";
|
$content.='"'.$row['username'].'","'.$row['unit'].'","'.$row['phone'].'","'.$row['address'].'","'.$row['postcode'].'","'.str_replace("\"","'",$row['project']).'","'.str_replace("\"","'",$row['datalist']).'","'.$row['email'].'",'.$row['ts_created']."\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
include_once("Output.php");
|
|
||||||
$output = new Output($this->db);
|
$output = new Output($this->db);
|
||||||
$output->Download("offlineapp.csv",$rows,"csv");
|
$output->Download("offlineapp.csv",$content,"string");
|
||||||
|
|
||||||
return true;
|
|
||||||
$this->getResponse()->setHeader('Content-Type', 'application/octet-stream')
|
|
||||||
->setHeader('Content-Disposition','attachment; filename="offlineapp.csv"')
|
|
||||||
->setHeader('Content-Length', strlen($content))
|
|
||||||
->setHeader('Content-Type','application/force-download')
|
|
||||||
->setHeader('Content-Type','application/download')
|
|
||||||
->setHeader('Content-Description','File Transfer')
|
|
||||||
->setHeader('Content-Transfer-Encoding','binary')
|
|
||||||
->setHeader('Expires',0)
|
|
||||||
->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0')
|
|
||||||
->setHeader('Pragma','public')
|
|
||||||
->setBody($content);
|
|
||||||
|
|
||||||
} //下载离线服务记录
|
} //下载离线服务记录
|
||||||
|
|
||||||
else if ($update) {
|
else if ($update) {
|
||||||
|
|
|
@ -27,6 +27,7 @@ class Output
|
||||||
"json"=>"JsonOutPut",
|
"json"=>"JsonOutPut",
|
||||||
"xml"=>"XMLOutPut",
|
"xml"=>"XMLOutPut",
|
||||||
"csv"=>"CSVOutPut",
|
"csv"=>"CSVOutPut",
|
||||||
|
"string"=>"StringOutPut",
|
||||||
);
|
);
|
||||||
|
|
||||||
$file_type_functions = array();
|
$file_type_functions = array();
|
||||||
|
@ -64,6 +65,16 @@ class Output
|
||||||
|
|
||||||
}//JsonOutPut()
|
}//JsonOutPut()
|
||||||
|
|
||||||
|
public function StringOutPut($content){
|
||||||
|
if(strpos($_SERVER["HTTP_USER_AGENT"],"Windows"))
|
||||||
|
{
|
||||||
|
$head = "\xEF\xBB\xBF";
|
||||||
|
}else{
|
||||||
|
$head = "";
|
||||||
|
}
|
||||||
|
return $head.$content;
|
||||||
|
}
|
||||||
|
|
||||||
//输出CSV内容
|
//输出CSV内容
|
||||||
public function CSVOutPut($data,$head = ""){
|
public function CSVOutPut($data,$head = ""){
|
||||||
|
|
||||||
|
@ -90,10 +101,12 @@ class Output
|
||||||
|
|
||||||
foreach($v as $kk=>$vv)
|
foreach($v as $kk=>$vv)
|
||||||
{
|
{
|
||||||
if(strpos($vv,","))
|
if(strpos($vv,"\""))
|
||||||
{
|
{
|
||||||
$v[$kk] = "\"".$vv."\"";
|
$vv = preg_replace("/\"/",'""',$vv);
|
||||||
}
|
}
|
||||||
|
$v[$kk] = "\"".$vv."\"";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$content .= join($split,$v)."\r\n";
|
$content .= join($split,$v)."\r\n";
|
||||||
|
|
Loading…
Reference in New Issue