map200uk Posted May 10, 2007 Share Posted May 10, 2007 hi, i am working on a library for digital audio, and as such streaming would be nice, i was implementing streaming by creating a playlist with the value of $_GET[path] from when the user selects the file to be streamed however on the page where the playlist is created i had an if iif($action=="stream") { if(file_exists(file))) { unlink(file); } addtoplaylist(); createPlaylist("webstream.pls"); $filename = "stream.pls"; $myFile = "webstream.pls"; $mm_type="application/octet-stream"; header("Cache-Control: public, must-revalidate"); header("Pragma: hack"); // header("Content-Type: " . $mm_type); header("Content-Length: " .(string)(filesize($myFile)) ); header('Content-Disposition: attachment; filename="'.$filename.'"'); header("Content-Transfer-Encoding: binary\n"); readfile($myFile); } ?> now the thing is when i click a song to stream i get the PLS file but it contains html, would this be because i am sending other data before the header? I have used ob_start() the functions are in the same file, playlist.php bit confused mark Quote Link to comment https://forums.phpfreaks.com/topic/50863-php-headers/ Share on other sites More sharing options...
btherl Posted May 11, 2007 Share Posted May 11, 2007 What html does the PLS file contain? Quote Link to comment https://forums.phpfreaks.com/topic/50863-php-headers/#findComment-250246 Share on other sites More sharing options...
map200uk Posted May 11, 2007 Author Share Posted May 11, 2007 it contains the html of the main page i.e. the index if i dont have the functions in place and just make it push a .pls to the user it works fine? Yet with the functions in placwe it does not and i have cat the .pls file and the contents are correct, but the user doesnt get them Quote Link to comment https://forums.phpfreaks.com/topic/50863-php-headers/#findComment-250248 Share on other sites More sharing options...
map200uk Posted May 11, 2007 Author Share Posted May 11, 2007 function createStream() { $song=$_GET['path']; if(file_exists("webstream.pls")) { unlink("webstream.pls"); } if (!$file_handle = fopen("webstream.pls","a")) { echo "Cannot open file"; } $fileheader="[playlist]\n"; $numentries="NumberOfEntries=1"."\n"; if (!fwrite($file_handle, $fileheader)) { echo "Cannot write to file"; } if (!fwrite($file_handle, $numentries)) { echo "Cannot write to file"; } if (!fwrite($file_handle, $song)) { echo "Cannot write to file"; } return true; } thats for creating the playlist, then if($action=="createpls") { createPlaylist($playlistname); } which creates the playlist for the stream correctly, cat webstream.pls [playlist] NumberOfEntries=1 http://148.197.34.121/mp3/aphex_twin-05-i-rns.mp3 however when i add in $filename = "ymms_stream.pls"; $myFile = "/opt/lampp/htdocs/www.itsallagamble.co.uk/phpdb/webstream.pls"; $mm_type="application/octet-stream"; header("Cache-Control: public, must-revalidate"); header("Pragma: hack"); header("Content-Type: " . $mm_type); header("Content-Length: " .(string)(filesize($myFile)) ); header('Content-Disposition: attachment; filename="'.$filename.'"'); header("Content-Transfer-Encoding: binary\n"); readfile($myFile); it goes to pot surely it should be fine? create file, then push it to the user if the file is already there-and we dont create it when action==stream then the file (existing) gets pushed to user without a problem, and it does not contain html i cant see where rthe html comes from?! even with all the code in, the file created is correct-not full of html?! Quote Link to comment https://forums.phpfreaks.com/topic/50863-php-headers/#findComment-250261 Share on other sites More sharing options...
map200uk Posted May 11, 2007 Author Share Posted May 11, 2007 whats confusing me even more is, if i change the code to make it dopwnload an m3 file, rather than a playlist, it works fine?! Quote Link to comment https://forums.phpfreaks.com/topic/50863-php-headers/#findComment-250265 Share on other sites More sharing options...
map200uk Posted May 11, 2007 Author Share Posted May 11, 2007 <htm> <head> <title></title> <style type="text/css" media="screen"> body { margin:0; padding:0; height:100%; } #header { height: 50px; background-color: #EAEAEA; width: 100%; border:1px solid #333; padding:4px; } #left { position:absolute; left:0; top:80px; padding:0; width:200px; height:60%; color:#333; background:#eaeaea; border:1px solid #333; } .content { position: relative; top: 30px; margin-left:220px; margin-right:220px; margin-bottom:20px; color:#333; background:#ffc; width: 1200px; border:1px solid #333; padding:0 10px; } #right { position:absolute; right:0; left: 100%; top: 80px; padding:0; width:200px; height:60%; color:#333; background:#eaeaea; border:1px solid #333; } #left p { padding:0 10px; } #right p { padding:0 10px; } p.top { margin-top:20px; } </style> </head> <body> <div id="header"> <p><b>Ymms- It's the future</b>.</p> </div> <div id="left"> <p class="top"><ul><li><a href=//phpdb/laytest.php?page=main>Home</a></li> <li><a href=laytest.php?page=search >Search</a></li> </div> <div class="content"> <p>include page here?.gfhddff</p> Array ( => playlist [action] => stream [path] => http://148.197.34.121/mp3/24-03-l.a_at_9.00_a.m.mp3 ) Array ( ) [playlist] NumberOfEntries=1 http://148.197.34.121/mp3/aphex_twin-05-i-rns.mp3 </div> </body> </html> thats the contents of a .pls which is oushed to the user-could this be because of readfile putting the playlist into a buffer with the actual page? altho...it works fine for mp3? map Quote Link to comment https://forums.phpfreaks.com/topic/50863-php-headers/#findComment-250268 Share on other sites More sharing options...
map200uk Posted May 11, 2007 Author Share Posted May 11, 2007 just tried with a text file and noticed the same thing, the html is put into the file anyone got any suggestions?:| Quote Link to comment https://forums.phpfreaks.com/topic/50863-php-headers/#findComment-250269 Share on other sites More sharing options...
map200uk Posted May 11, 2007 Author Share Posted May 11, 2007 and i also just noticed when i opened the contents of the mp3 file-it seems to do the same to the html file (altho it still plays fine) it does add junk Quote Link to comment https://forums.phpfreaks.com/topic/50863-php-headers/#findComment-250270 Share on other sites More sharing options...
map200uk Posted May 11, 2007 Author Share Posted May 11, 2007 bump anyone?? Quote Link to comment https://forums.phpfreaks.com/topic/50863-php-headers/#findComment-250437 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.