tbszip下载
include_once('extend/tbszip.php');
$zip = new \clsTbsZip();
$path = 'Public/File/2022/'; //docx文件所在目录
$filelist=scandir($path);
foreach($filelist as $ks=>$vs) {
if ($vs=='.' || $vs=='..' || $vs=='.DS_Store') {
continue;
}
$zip->Open($path.$vs);
$content1 = $zip->FileRead('word/document.xml');
$zip->Close();
$p = strpos($content1, '<w:body');
if ($p===false) exit("失败");
$p = strpos($content1, '>', $p);
$content1 = substr($content1, $p+1);
$p = strpos($content1, '</w:body>');
if ($p===false) exit("失败");
$content1 = substr($content1, 0, $p);
$strs='<w:p><w:pPr><w:rPr><w:sz w:val="21"/><w:szCs w:val="21"/></w:rPr></w:pPr></w:p><w:p/><w:p/><w:p/><w:p/><w:p/><w:p/><w:p/><w:p/><w:p><w:pPr><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/></w:rPr></w:pPr></w:p><w:p/><w:p/><w:p/><w:p/><w:p/><w:p><w:r><mc:AlternateContent>';
$oldstrs='<w:p><w:pPr><w:rPr><w:sz w:val="21"/><w:szCs w:val="21"/></w:rPr></w:pPr></w:p><w:p/><w:p/><w:p/><w:p/><w:p/><w:p/><w:p/><w:p/><w:p><w:pPr><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/></w:rPr></w:pPr></w:p><w:p/><w:p/><w:p/><w:p><w:r><mc:AlternateContent>';
$content1=str_replace($strs,$oldstrs,$content1);
$contents[]=$content1;
}
$zip->Open($path."/empty.docx"); // 空的docx文件
$content2 = $zip->FileRead('word/document.xml');
$p = strpos($content2, '</w:body>');
if ($p===false) exit("失败");
$content2 = substr_replace($content2, implode('',$contents), $p, 0);
$zip->FileReplace('word/document.xml', $content2, TBSZIP_STRING);
$savePath='Public/Write/merges.docx';
// 合并docx文件存储地址
$zip->Flush(TBSZIP_FILE,$savePath);
//或者输出下载
header("Cache-Control: public");
header("Content-Description: File Transfer");
header('Content-disposition: attachment; filename='.basename($zipfilename)); //文件名
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header('Content-Length: '. filesize($savePath)); //告诉浏览器,文件大小
readfile($savePath);
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!