开发者

What php Headers do I need to play an audio file

I have decrypted my audio file, I now want to play it and then unlink it. What I currently have is:

<?php
    $destination = "/tmp_upload_dir_copy/test.mp3"
    header('Content-Type: audio/mpeg');
    readfile($destination); 
    unlink($destination);
?>

Anyone have any ideas what I'm 开发者_如何学编程doing wrong or what else do I need?

maybe I need to use fpassthru() ?


PHP works only server side. You can only guarentee the file is SENT to the client, but there is no way to directly make sure it has been PLAYED by the client.

Setting the header will only influence how the browser treats the data (in this case the browser is informed the data is audio). Chrome, for example plays audio files but some browsers may give users a download prompt.

You'll need client side software, like a audio playing component (search "Flash MP3 player") to embed in a page to play the audio file.


Sounds like you don't really want to delete the file immediately, as any number of things could go wrong on the user's end between downloading the mp3 and actually playing it. The user might need to initiate the file transfer again in many cases. Instead you might want to set up a cron job that runs every night and deletes the mp3 files that are more than one day old. (Also, I'm not sure what you meant by "decrypt" the audio file.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜