CODE
require_once('pclzip.lib.php');
$template='pliczek.odt';
$temp_dir=time();
mkdir ($temp_dir, 0777);
copy('templates/'.$template, $temp_dir.'/'.$template);
$archive = new PclZip($temp_dir.'/'.$template);
if ($archive->extract(PCLZIP_OPT_BY_NAME, 'content.xml',
PCLZIP_OPT_PATH,$temp_dir) == 0) {
die("Error : ".$archive->errorInfo(true));
}
if ($archive->extract(PCLZIP_OPT_BY_NAME, 'mimetype',
PCLZIP_OPT_PATH,$temp_dir) == 0) {
die("Error : ".$archive->errorInfo(true));
}
$mimetype = file_get_contents($temp_dir.'/mimetype');
$content=file_get_contents($temp_dir.'/content.xml');
// tutaj jest cała zamiana
$content = str_replace('{znacznik1}',utf8_encode('ęóąśłżźćń'), $content);
$content = str_replace('{znacznik2}',utf8_encode('TEKST2'), $content);
//koniec
$handle=fopen($temp_dir."/content.xml","w");
fwrite($handle,$content);
fclose($handle);
$archive = new PclZip($temp_dir.'/'.$template);
$v_list = $archive->add($temp_dir.'/content.xml',PCLZIP_OPT_REMOVE_PATH, $temp_dir);
if ($v_list == 0) {
die("Error : ".$archive->errorInfo(true));
}
Header("Content-Disposition: attachment; filename=$template");
Header("Content-Type: $mimetype");
echo file_get_contents($temp_dir.'/'.$template);
unlink($temp_dir.'/content.xml');
unlink($temp_dir.'/mimetype');
unlink($temp_dir.'/'.$template);
rmdir($temp_dir);
$template='pliczek.odt';
$temp_dir=time();
mkdir ($temp_dir, 0777);
copy('templates/'.$template, $temp_dir.'/'.$template);
$archive = new PclZip($temp_dir.'/'.$template);
if ($archive->extract(PCLZIP_OPT_BY_NAME, 'content.xml',
PCLZIP_OPT_PATH,$temp_dir) == 0) {
die("Error : ".$archive->errorInfo(true));
}
if ($archive->extract(PCLZIP_OPT_BY_NAME, 'mimetype',
PCLZIP_OPT_PATH,$temp_dir) == 0) {
die("Error : ".$archive->errorInfo(true));
}
$mimetype = file_get_contents($temp_dir.'/mimetype');
$content=file_get_contents($temp_dir.'/content.xml');
// tutaj jest cała zamiana
$content = str_replace('{znacznik1}',utf8_encode('ęóąśłżźćń'), $content);
$content = str_replace('{znacznik2}',utf8_encode('TEKST2'), $content);
//koniec
$handle=fopen($temp_dir."/content.xml","w");
fwrite($handle,$content);
fclose($handle);
$archive = new PclZip($temp_dir.'/'.$template);
$v_list = $archive->add($temp_dir.'/content.xml',PCLZIP_OPT_REMOVE_PATH, $temp_dir);
if ($v_list == 0) {
die("Error : ".$archive->errorInfo(true));
}
Header("Content-Disposition: attachment; filename=$template");
Header("Content-Type: $mimetype");
echo file_get_contents($temp_dir.'/'.$template);
unlink($temp_dir.'/content.xml');
unlink($temp_dir.'/mimetype');
unlink($temp_dir.'/'.$template);
rmdir($temp_dir);