服务器上的PHPWord文件已损坏,某些部分已丢失

服务器上的PHPWord文件已损坏,某些部分已丢失,php,file,server,phpword,corrupted-state-exception,Php,File,Server,Phpword,Corrupted State Exception,我已经用Composer和Wamp64在我的计算机上安装了PHPWord。 使用一个模板,在我的计算机上,模板被很好地修改,文件的录制也很完美。 在infomaniak服务器上,我收到一条消息,文件已损坏,并且缺少一些部分。 我找不到原因。这是我的密码。 请帮我找到问题的根源 <?php $docModele = 'print/modele_cdd_as_2.docx'; require_once '../PhpWord/bootstrap.php'; use\PhpOffice\Ph

我已经用Composer和Wamp64在我的计算机上安装了PHPWord。 使用一个模板,在我的计算机上,模板被很好地修改,文件的录制也很完美。 在infomaniak服务器上,我收到一条消息,文件已损坏,并且缺少一些部分。 我找不到原因。这是我的密码。 请帮我找到问题的根源

<?php 
$docModele = 'print/modele_cdd_as_2.docx';
require_once '../PhpWord/bootstrap.php';

use\PhpOffice\PhpWord\PhpWord;

// Creating the new document...
$PHPWord = new \PhpOffice\PhpWord\PhpWord();
header('Content-type: application/json; charset=UTF-8');

/* Note: any element you append to a document must reside inside of a Section. */

$document = $PHPWord->loadTemplate($docModele);

$document->setValue('date_debut', $date_debut);
$document->setValue('identite', $identite.' ');
$document->setValue('date_naissance', $date_naissance);
$document->setValue('lieu_naissance', $lieu_naissance);
$document->setValue('dpt_naissance', $dpt_naissance);
$document->setValue('adresse1', $adresse1);
$document->setValue('cp', $cp);
$document->setValue('ville', $ville);
$document->setValue('no_ss', $no_ss);
$document->setValue('jour_debut', $jour_debut);
$document->setValue('date_fin', $date_fin);
$document->setValue('remplace', $remplace);
$document->setValue('motif_txt', $motif_txt);
$document->setValue('essai', $essai);
$document->setValue('indice', $indice);
$document->setValue('valeur_point', $valeur_point);
$document->setValue('brut', $brut);
$document->setValue('majoration', $majoration);
$document->setValue('date_contrat', $date_contrat);


//XML Writer compatibility
\PhpOffice\PhpWord\Settings::setCompatibility(false);

//#####################################################
// Save File
//#####################################################
//#####################################################
ob_clean();

$filename = 'nom_du_fichier.docx';
header("Content-Disposition: attachment; filename=$filename");
$document->saveAs('php://output');
//#####################################################
//#####################################################
exit;

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($PHPWord, 'Word2007');

// création du fichier

$objWriter->save($filename);

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($filename));
ob_clean();
flush();
readfile($filename);
unlink($filename); // deletes the temporary file
saveAs('php://output');
//#####################################################
//#####################################################
出口
$objWriter=\PhpOffice\PhpWord\IOFactory::createWriter($PhpWord,'Word2007');
//费希尔公寓
$objWriter->save($filename);
标题(“内容描述:文件传输”);
标题(“内容类型:应用程序/八位字节流”);
标题('Content-Disposition:attachment;filename='。$filename);
标题(“内容传输编码:二进制”);
标题('Expires:0');
标头('Cache-Control:必须重新验证,后检查=0,前检查=0');
标题(“Pragma:public”);
标题('Content-Length:'.filesize($filename));
ob_clean();
冲洗();
readfile($filename);
取消链接($filename);//删除临时文件

?>

执行此脚本时,是否检查服务器日志以查找警告?每台服务器都不同—您可能缺少一个库,或者硬件资源不足以运行脚本,或者编码不同。检查日志,看看有没有什么。我还看到您使用$document->saveAs('php://output'); 所以可能是文件太重了。请尝试将文档保存在磁盘上,以查看是否存在相同的错误(基本上是在退出后使用此功能;)谢谢您的“服务器日志中没有任何警告”谢谢您的警告。我没有关于服务器日志的报告。在光盘上保存时也会出现同样的错误。在我看来,所有的图书馆都安装得很好。我还更改了编码。我暂时找不到问题的根源。我将尝试联系Infomaniak,看看他们是否能帮助meI刚才在服务器上发现此错误:[08/Jun/2021:12:28:53+0200]“GET/contrats/pg_print.php HTTP/1.1“200 86631”“”Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,如Gecko)Chrome/91.0.4472.77 Safari/537.36”。你能帮我解决吗?ThksInfomanaik说这不是日志错误,而是连接日志。他们方面没有错误。我将再次尝试验证,但我无法找到问题的根源。即使演示模板文件也不起作用