1
我已经从web服务输出一个文档下面的PHP代码:AngularJS FileSaver产生空文件
$db->where('documentReference', $post->documentID);
$results = $db->getOne('documents');
$filelocation = 'doc/';
$file = $results['filename'];
header('Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Length: ' . filesize($filelocation.$file));
header('Content-disposition: attachment; filename="'.$file.'"');
readfile($filelocation.$file);
而且在前端..
APIService.registerUser($scope.formData).then(function(data){
var blob = new Blob([data.data], {type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'});
var config = {
data: blob,
filename: 'test.docx'
};
FileSaver.saveAs(config);
});
}
当我检查返回的数据从API文档返回正常,但保存时它总是空的?
此外,如果您从PHP返回,请确保您在关闭后没有换行符?> –