Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7491153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:55:53+00:00 2026-05-29T15:55:53+00:00

I need to stream a media file from another server through this php file.

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:55:54+00:00Added an answer on May 29, 2026 at 3:55 pm

    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/mpeg in 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:

    <?php
    
      // Try and open the remote stream
      if (!$stream = fopen('http://example.com/audio.mp3', 'r')) {
        // If opening failed, inform the client we have no content
        header('HTTP/1.1 500 Internal Server Error');
        exit('Unable to open remote stream');
      }
    
      // It's probably an idea to remove the execution time limit - on Windows hosts
      // this could result in the audio stream cutting off mid-flow
      set_time_limit(0);
    
      // Inform the client we will be sending it some MPEG audio
      header('Content-Type: audio/mpeg');
    
      // Send the data
      fpassthru($stream);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to stream a file from my server to several clients. I'm not
I need to stream an audio file which is saved on my server. Is
I recieve a Stream and need to pass in a IEnumerable to another method.
I have an application the requests a media stream from a server, however the
I need to download a mp3 file from a server URL, and then play
I need to stream webcam/microphone data from a browser to my server: Can I
I need stream video from my webcam to ISS Media Services like it does
I need to stream a file to the Response for saving on the end
I need to stream an flv file. Streaming should look like live streaming, and
I need to know how I get the stream of the headers and footers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.