0

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');
       });

誰かがアイデアを持っていますか?

4

1 に答える 1

0

私も同じ問題を抱えていました。responseType: 'arraybuffer'get 構成に追加するだけです。

于 2015-06-17T13:42:36.330 に答える