首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >转换时PHP下载文件

转换时PHP下载文件
EN

Stack Overflow用户
提问于 2019-05-21 04:48:10
回答 1查看 45关注 0票数 0

我需要一种方法来下载一个mp3文件,同时从m4a转换为mp3。

我试过这个代码,它可以工作,但是,当我播放歌曲时,它有错误的持续时间,如果歌曲有3分钟的长度,那么当通过这个函数下载时,它的长度是3:40左右

代码语言:javascript
复制
set_time_limit(0);
$local_file = 'song.mp3';
$download_file = 'song.mp3';
if(file_exists($local_file) && is_file($local_file)) {
header('Content-Description: file transfer');
header('Content-Disposition: attachment; filename='.$download_file);
header("Content-Transfer-Encoding: binary"); 
header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3"); 
$perSecond = 500000; 
$file = fopen($local_file, 'r');
while(!feof($file)) {
    echo fread($file, $perSecond);
    flush();
    sleep(11);
}

}

有没有办法做到这一点?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2019-05-21 04:54:21

也许可以使用sendfile来流式传输文件?当对非文本文件使用fopen时,使用b标志指定二进制模式:fopen($path, 'rb')

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56227982

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档