SLIM Framework で記述された PHP REST API があります。docx ファイルを作成し、ファイルを強制的にダウンロードする API 呼び出しがあります。
$filename = 'invitation.docx';
$templateProcessor->save($filename);
header('Content-Description: ファイル転送');
header('Content-type: アプリケーション/強制ダウンロード');
header('Content-Disposition: attachment; filename='.basename($filename));
header('Content-Transfer-Encoding: バイナリ');
header('Content-Length: '.filesize($filename));
ob_clean();
ob_flush();
readfile($ファイル名);
出口();
ファイルが作成され、サーバー経由で読み取ることができます。しかし、問題はクライアント側にあり、ファイルが破損しています
Data.get('downloadInvitation/'+ id).then(function(results) {
var file = new Blob([results], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
saveAs(file, 'invitation.docx');
});
誰かがアイデアを持っていますか?