2008年2月25日 星期一

從基本得做起ooo_basic.php

ooo_basic.php位於x_schdule,目的是產生ooo檔案
function outputooofile($ooo_path,$filename,$temp_arr)
$ooo_path 解壓縮檔的位置
$filename 輸出的檔案名稱
$temp_arr 置換的tag名

原始碼
include_once "../x_base/sxsooo_class.php";
function outputooofile($ooo_path,$filename,$temp_arr) { //新增一個 zipfile 實例 $ttt = new zipfile;
if (is_dir($ooo_path)) { if ($dh = opendir($ooo_path)) { while (($file = readdir($dh)) !== false) { preg_match('/^(.)+\.odt$/',$file,$matches); if($file=="." or $file==".." or $file=="content.xml" or $matches[0]){ continue; }elseif(is_dir($ooo_path."/".$file)){ if($file=="Configurations2") $file_extname="odt"; if ($dh2 = opendir($ooo_path."/".$file)) { while (($file2 = readdir($dh2)) !== false) { if($file2=="." or $file2==".."){ continue; }else{ if($dh3 = opendir($ooo_path."/".$file."/".$file2)){ while (($file3 = readdir($dh3)) !== false) { if($file3=="." or $file3==".."){ //continue; }else{ $data = $ttt->read_file($ooo_path."/".$file."/".$file2."/".$file3); $ttt->add_file($data,$file."/".$file2."/".$file3); } } closedir($dh3); }else{ $data = $ttt->read_file($ooo_path."/".$file."/".$file2); $ttt->add_file($data,$file."/".$file2); } } } closedir($dh2); } }else{ $data = $ttt->read_file($ooo_path."/".$file); $ttt->add_file($data,$file); } } closedir($dh); } } //讀出 content.xml $data = $ttt->read_file($ooo_path."/content.xml"); if($file_extname=="odt") { $filename.=".odt"; } else { $filename.=".sxw"; } $replace_data = $ttt->change_temp($temp_arr,$data,0); $replace_data = $con_head.$replace_data.$con_foot;
//把一些多餘的標籤以空白取代 $pattern[]="/\{([^\}]*)\}/"; $replacement[]="";
$replace_data=preg_replace($pattern, $replacement, $replace_data); //$replace_data=str_replace ('
', '', $replace_data);
$ttt->add_file($replace_data,"content.xml");
//產生 zip 檔 $sss = $ttt->file();
//以串流方式送出 ooo.sxw if(strpos($_SERVER['HTTP_USER_AGENT'] , 'MSIE') strpos($_SERVER['HTTP_USER_AGENT'] , 'Opera')) $mimeType="application/x-download"; elseif($file_extname=="odt") $mimeType="application/vnd.oasis.opendocument.text"; else $mimeType="application/vnd.sun.xml.writer"; header("Content-disposition: attachment; filename=$filename"); header("Content-type: $mimeType ");
echo $sss;
exit;

沒有留言: