gpt4 book ai didi

php - 带标题下载的文件不起作用

转载 作者:行者123 更新时间:2023-12-03 01:37:20 24 4
gpt4 key购买 nike

我正在尝试下载具有动态网址的音频ogg文件

function getAudio($fileName){

$localFile = __DIR__ . '/../../../shared/call_review/' . $fileName;
$fp = fopen($localFile, 'r');
$fp or die('Could not open file "' . $fileName . '"' . PHP_EOL);

$contents = fread($fp, filesize($localFile));
$contents or die('could not read file');

header('Content-Description: File Transfer');
header('Cache-Control: public');
header('Content-Type: audio/ogg');
header("Content-Transfer-Encoding: binary");
header('Content-Length: '.filesize($contents));
header("Content-Type: audio/ogg");
header("Content-Disposition: attachment; filename=" . $fileName);

echo $contents;
exit();
}

但是保存文件后,它不起作用或损坏。

最佳答案

问题似乎是这一行:

header('Content-Length: '.filesize($contents));

文件大小应来自 filesize($localFile),如前面几行所示,
所以应该是:
header('Content-Length: '.filesize($localFile));

或者只使用 $contents变量的长度:
header('Content-Length: '.strlen($contents));

关于php - 带标题下载的文件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51325200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com