I need to stream a media file from another server through this php file.
<?php
$out = array(
'http'=>array(
'method'=>"GET",
'header'=>"Content-type: audio/mpeg\r\n",
)
);
$stream = stream_context_create($out);
$end = fopen('http://example.com/audio.mp3', 'r', false, $stream);
fpassthru($end);
readfile($end);
?>
But the header doesn’t work.
How can I fix this?
You are sending the header in the wrong direction. What you have done is informed the source server that you will be sending it some
audio/mpegin a GET request – which is invalid anyway, GET requests don’t have content. What you actually need to do is send it to the client who will be receiving the content.You shouldn’t need the stream context for this task – try this code: