如何从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)) {
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();