だからここに私のコードがあります:
<?php
$zip = new ZipArchive;
if ($zip->open('test.docx') === TRUE) {
$xmlString = $zip->getFromName('word/document.xml');
$xmlString = str_replace('$FIRST_AND_LAST_NAME', 'John Doe', $xmlString);
$zip->addFromString('word/document.xml', $xmlString);
echo 'ok';
$zip->close();
} else {
echo 'failed';
}
その目的は単純です。test.docx ファイルを開き、"$FIRST_AND_LAST_NAME" という文字列をすべて検索して "John Doe" に置き換えます。
これは、私の Windows 開発サーバーで完全に動作します (「John Doe」という文字列は、ドキュメントを開くとドキュメントに含まれています)。
私の Lnux 本番サーバーでは機能しません (「$FIRST_AND_LAST_NAME」文字列はまだ存在しますが、「John Doe」はありません)。
エラーや通知はありません。「ok」はエラーなしで出力されます。test.docx ファイルの権限が 777 に設定されていることを確認しました。