使用angularjs从PHP REST API下载docx文件
我有一个使用SLIM Framework编写的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(); 该文件已创建,我可以通过服务器读取它。 但问题是在客户端文件已损坏
Data.get('downloadInvitation/'+ id).then(function(results) {
var file = new Blob([results], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
saveAs(file, 'invitation.docx');
});
有没有人有想法?
我有同样的问题。 只需将responseType: 'arraybuffer'添加到您的get配置中即可。
