在php中将二进制文件转换为Blob
如何在php中从二进制文件创建blob对象?这是我最后的代码:在php中将二进制文件转换为Blob,php,binary,blob,Php,Binary,Blob,如何在php中从二进制文件创建blob对象?这是我最后的代码: foreach ($results as $key) { $content = base64_decode($key['file_proposal']); $file = $key['nama_file_proposal']; file_put_contents($file, $content); if (file_exists($file)) {
foreach ($results as $key) {
$content = base64_decode($key['file_proposal']);
$file = $key['nama_file_proposal'];
file_put_contents($file, $content);
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
我的代码生成错误消息“文件格式或文件扩展名无效”,所以我想将$content更改为blob对象,因为我在js中创建了下载文件的代码,但它使用blob。这是我的js代码:
const url = window.URL.createObjectURL(new Blob([response.data], {type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'Detail Blast.xlsx');
document.body.appendChild(link);
link.click();
你能解释一下“水滴”是什么意思吗?就像示例输入和所需输出一样?@mario done,我编辑了我的问题:)您的代码在这里工作。怎么了?@FelippeDuarte我可以下载我的文件。但当我打开它时,它会产生“文件格式或文件扩展名无效”的错误消息。我应该怎么做?什么是响应数据?