Post
#1
|
|
|
Grupa: Zarejestrowani Postów: 8 Pomógł: 0 Dołączył: 5.12.2007 Ostrzeżenie: (0%)
|
Witam. Mam skrypt który pozwala mi z poziomu php edytować pliki OO, robi to przez zamiane wcześniej ustawionych znaczników w dokumencie. Niestety problem pojawia się gdy chce wkleić do niego polskie znaki (wychodzą krzaczki). Przedstawiam skrypt reaizujący tą zamiane.
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); |
|
|
|
![]() ![]() |
|
Aktualny czas: 25.12.2025 - 15:43 |