使用angularjs从PHP REST API下载docx文件
我有一个用SLIM框架编写的PHP REST API,我有一个API调用,它创建一个docx文件并强制下载该文件。 $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();使用angularjs从PHP REST API下载docx文件,php,angularjs,rest,slim,phpword,Php,Angularjs,Rest,Slim,Phpword,我有一个用SLIM框架编写的PHP REST API,我有一个API调用,它创建一个docx文件并强制下载该文件。 $filename = 'invitation.docx'; $templateProcessor->save($filename); header('Content-Description: File Transfer'); header('Content-type: application/force-download'); header('Co
有人有想法吗?我也有同样的问题。只需在get配置中添加
responseType:'arraybuffer'
Data.get('downloadInvitation/'+ id).then(function(results) {
var file = new Blob([results], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
saveAs(file, 'invitation.docx');
});