Stream MP3 using PHP – m3u


Hits: 6697  

M3U is a computer file format that stores multimedia playlists.

<?php

function m3u_stream($dir) {

$mp3=””;
$siteurl=”http://www.domain.com/mp3/”;

$h1 = opendir($dir);

while ($file = readdir($h1))
{

if ($file == ‘.’ || $file == ‘..’) continue;
$mp3.=$siteurl.basename($dir).”/”.$file.”\r\n”;

}

closedir($h1);

return $mp3;

}

$folder = “svnlabs”;

file_put_contents($folder.”.m3u”, m3u_stream($_SERVER[“DOCUMENT_ROOT”].”/mp3/”.$folder.”/”));

?>

Here “svnlabs” is a folder where all mp3 files exists… this program will create svnlabs.m3u playlist file using php script.

svnlabs.m3u file contents all mp3 links with domain “http://www.domain.com/mp3/”

svnlabs.m3u
………………



……………………

Now http://www.domain.com/mp3/svnlabs.m3u can be used for streaming mp3 from www.domain.com

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch

21 thoughts on “Stream MP3 using PHP – m3u”

  1. Sometimes we need to download files as attachment in PHP. This code can ideally be called on a hyperlink.

    $filename = “myImage.jpg”;

    if(file_exists($filename)) {

    header(“Content-disposition: attachment; filename={$filename}”);

    //Tell the filename to the browser

    header(‘Content-type: application/octet-stream’);

    //Stream as a binary file! So it would force browser to download

    readfile($filename);

    //Read and stream the file

    }else{

    echo “Sorry, the file does not exist!”;

    }

    ——————–

    Source:

    http://phphelp.co/2012/06/13/how-to-stream-a-file-as-attachment-in-php/

    OR

    http://addr.pk/a988

  2. When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with
    the same comment. Is there any way you can remove people from
    that service? Many thanks!

  3. Howdy would you mind letting me know which webhost you’re utilizing?

    I’ve loaded your blog in 3 completely different web browsers and I must say this blog loads a lot quicker then most.

    Can you suggest a good web hosting provider at a honest price?
    Many thanks, I appreciate it!

  4. If you desire to increase your familiarity simply keep visiting this web page
    and be updated with the newest gossip posted here.

  5. I was recommended this blog by means of my cousin.
    I am not certain whether this publish is written by him
    as nobody else understand such specific about my difficulty.

    You’re incredible! Thanks!

  6. I have been exploring for a little for any high-quality articles
    or weblog posts on this sort of area . Exploring in Yahoo I ultimately stumbled upon this site.
    Reading this information So i’m happy to exhibit that I’ve an incredibly good uncanny feeling I discovered exactly
    what I needed. I so much undoubtedly will make sure to do not forget this web site
    and provides it a glance on a continuing basis.

  7. I love your blog.. very nice colors & theme.
    Did you make this website yourself or did you hire someone to do it for you?
    Plz reply as I’m looking to construct my own blog and would like
    to find out where u got this from. thanks a lot

  8. Its such as you learn my mind! You seem to grasp a lot approximately this, like you wrote the ebook in it or something.
    I feel that you simply could do with a few % to drive the message home a little bit,
    however instead of that, this is wonderful blog. A fantastic read.
    I’ll definitely be back.

  9. Hey there! This post couldn’t be written any better!
    Reading through this post reminds me of my old room mate!
    He always kept chatting about this. I will forward this write-up
    to him. Fairly certain he will have a good read.
    Thanks for sharing!

  10. Hmm it appears like your website ate my first comment (it was extremely long) so I guess I’ll just sum it
    up what I wrote and say, I’m thoroughly enjoying your blog.
    I too am an aspiring blog writer but I’m still new to everything.
    Do you have any tips and hints for beginner blog writers?

    I’d genuinely appreciate it.

Leave a Reply

Your email address will not be published.

*