#284 后台下载全部元数据xml文件
This commit is contained in:
parent
bc29229463
commit
9421ae190d
|
@ -332,42 +332,77 @@ class Admin_DataController extends Zend_Controller_Action
|
||||||
|
|
||||||
}//编辑附件
|
}//编辑附件
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 输出打包下载的xml文件
|
||||||
|
*
|
||||||
|
* 文件量大时可能出现超时,需要修改超时时间为无限
|
||||||
|
*/
|
||||||
elseif ($down) {
|
elseif ($down) {
|
||||||
$zip = new ZipArchive();
|
|
||||||
$url="/tmp/xml.zip";
|
|
||||||
$opened=$zip->open($url, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
|
|
||||||
if( $opened !== true ){
|
|
||||||
die("cannot open {$url} for writing.");
|
|
||||||
}
|
|
||||||
$dirName = '../data/import/';
|
|
||||||
$zip->addEmptyDir("xml/");
|
|
||||||
|
|
||||||
$filesToAdd = array();
|
$this->_helper->layout->disableLayout();
|
||||||
$dir = dir($dirName);
|
$this->_helper->viewRenderer->setNoRender();
|
||||||
while (false !== ($node = $dir->read())) {
|
|
||||||
if (($node == '..') || ($node == '.')) {
|
//临时zip文件名
|
||||||
continue;
|
$tmpname="dataxml";
|
||||||
}
|
|
||||||
if (is_file($dirName.$node)) {
|
//xml文件存放的缓存目录
|
||||||
$zip->addFile($dirName.$node,"xml/".$node);
|
$dirName = '../data/import/';
|
||||||
}
|
|
||||||
}
|
//查询需要创建的文件
|
||||||
$zip->close();
|
$sql = "SELECT md.title,md.uuid,x.* from xml x
|
||||||
$content=file_get_contents($url);
|
LEFT JOIN metadata md ON md.id=x.id";
|
||||||
$this->_helper->layout->disableLayout();
|
|
||||||
$this->_helper->viewRenderer->setNoRender();
|
$sth = $this->db->prepare($sql);
|
||||||
|
$sth->execute();
|
||||||
|
$rows = $sth->fetchAll(); //将结果储存,但不使用
|
||||||
|
|
||||||
|
//创建zip文件,创建成功后再使用查询结果
|
||||||
|
$zip = new ZipArchive();
|
||||||
|
$url = tempnam($this->config->temp->path,$tmpname);//创建临时文件
|
||||||
|
|
||||||
|
if( $zip->open($url, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true )
|
||||||
|
{
|
||||||
|
throw new Exception("cannot open {$url} for writing.");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($rows as $k=>$v)
|
||||||
|
{
|
||||||
|
|
||||||
|
$filename = $dirName.$v['uuid'].'.xml';
|
||||||
|
|
||||||
|
//创建xml文件
|
||||||
|
$handle = fopen($filename,"w");
|
||||||
|
fwrite($handle,$v['data']);
|
||||||
|
fclose($handle);
|
||||||
|
|
||||||
|
//添加到zip文件
|
||||||
|
//zip localname 直接使用UUID作为文件名
|
||||||
|
$zip->addFile($filename,$v['uuid'].".xml");
|
||||||
|
|
||||||
|
}
|
||||||
|
$zip->close();
|
||||||
|
|
||||||
|
//zip文件创建完成后删除服务器上的缓存文件,防止发生冗余
|
||||||
|
foreach($rows as $k=>$v)
|
||||||
|
{
|
||||||
|
$filename = $dirName.$v['uuid'].'.xml';
|
||||||
|
unlink($filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
//输出下载
|
||||||
|
$content=file_get_contents($url);
|
||||||
$this->getResponse()->setHeader('Content-Type', 'application/octet-stream')
|
$this->getResponse()->setHeader('Content-Type', 'application/octet-stream')
|
||||||
->setHeader('Content-Disposition','attachment; filename="'.basename($url).'"')
|
->setHeader('Content-Disposition','attachment; filename="dataxml.zip"')
|
||||||
->setHeader('Content-Length', strlen($content))
|
->setHeader('Content-Length', strlen($content))
|
||||||
->setHeader('Content-Type','application/force-download')
|
->setHeader('Content-Type','application/force-download')
|
||||||
->setHeader('Content-Type','application/download')
|
->setHeader('Content-Type','application/download')
|
||||||
->setHeader('Content-Type','application/zip')
|
->setHeader('Content-Type','application/zip')
|
||||||
->setHeader('Content-Description','File Transfer')
|
->setHeader('Content-Description','File Transfer')
|
||||||
->setHeader('Content-Transfer-Encoding','binary')
|
->setHeader('Content-Transfer-Encoding','binary')
|
||||||
->setHeader('Expires',0)
|
->setHeader('Expires',0)
|
||||||
->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0')
|
->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0')
|
||||||
->setHeader('Pragma','public')
|
->setHeader('Pragma','public')
|
||||||
->setBody($content);
|
->setBody($content);
|
||||||
}//down
|
}//down
|
||||||
else if($search){
|
else if($search){
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue