0
我有一個PHP REST API已經用SLIM框架編寫,我有一個API調用,它創建一個docx文件並強制文件被下載。 從PHP REST API下載docx文件與angularjs
$filename = 'invitation.docx'; $templateProcessor->save($filename); header('Content-Description: File Transfer'); header('Content-type: application/force-download'); header('Content-Disposition: attachment; filename='.basename($filename)); header('Content-Transfer-Encoding: binary'); header('Content-Length: '.filesize($filename)); ob_clean(); ob_flush(); readfile($filename); exit();該文件已創建,我可以通過服務器讀取它。
但問題是在客戶端的文件已損壞
Data.get('downloadInvitation/'+ id).then(function(results) {
var file = new Blob([results], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
saveAs(file, 'invitation.docx');
});
沒有人有一個想法?