Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/50863-php-headers/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/50863-php-headers/#findComment-250248
Share on other sites

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?!

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/50863-php-headers/#findComment-250261
Share on other sites


<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

Link to comment
https://forums.phpfreaks.com/topic/50863-php-headers/#findComment-250268
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.