合并未知数量的.mp3文件 [英] Combine an unknown number of .mp3 files

查看:90
本文介绍了合并未知数量的.mp3文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个:

$number = 1;
$mp3 = file_get_contents("http://example.com/text=".$value);
$file = md5($value)."-".$number.".mp3";
file_put_contents($file, $mp3);
$number++;

结果:创建abcdef-1.mp3abcdef-2.mp3abcdef-3.mp3.
现在我想将abcdef-1.mp3abcdef-2.mp3abcdef-3.mp3组合.

Result: create abcdef-1.mp3, abcdef-2.mp3, abcdef-3.mp3.
Now I want to combine abcdef-1.mp3 with abcdef-2.mp3 and abcdef-3.mp3.

这有效:

file_put_contents('abcdef.mp3',
file_get_contents('abcdef-1.mp3') .
file_get_contents('abcdef-2.mp3') .
file_get_contents('abcdef-3.mp3'));

但是不适合我的代码,因为abcdef不同.数字也一样.

But is not suitable for my code, because abcdef differ. Numbers too.

我尝试过:

$number = 1;
$mp3 = file_get_contents("http://example.com/text=".$value);
$file = md5($value)."-".$number.".mp3";
file_put_contents($file, $mp3);
file_put_contents(md5($value).".mp3", file_get_contents($file));
$number++;

结果:创建abcdef-1.mp3abcdef-2.mp3abcdef-3.mp3abcdef.mp3,但是当我播放时,只有abcdef-1.mp3. 问题出在哪里?

Result: create abcdef-1.mp3, abcdef-2.mp3, abcdef-3.mp3 and abcdef.mp3 but when I play it's only abcdef-1.mp3. Where is the problem?

推荐答案

您可以使用FILE APPEND标志调用file_put_contents.这样的事情应该起作用

You can call file_put_contents with the FILE APPEND flag. Something like this should work

$number = 1;
$mp3 = file_get_contents("http://example.com/text=".$value);
$file = md5($value).".mp3";
file_put_contents($file, $mp3, FILE_APPEND);
$number++;

这篇关于合并未知数量的.mp3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆