首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复流的这个头?

如何修复流的这个头?
EN

Stack Overflow用户
提问于 2012-02-08 18:02:58
回答 2查看 2.2K关注 0票数 0

我需要通过此php文件从另一台服务器流式传输媒体文件。

代码语言:javascript
复制
<?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);
?>

但是报头不起作用。我该如何解决这个问题呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-02-08 18:12:31

您将标题发送到错误的方向。您所做的是通知源服务器,您将在GET请求中向其发送一些audio/mpeg -这无论如何都是无效的,GET请求没有内容。您实际需要做的是将其发送给将接收内容的客户端。

你应该不需要这个任务的流上下文--试试下面的代码:

代码语言:javascript
复制
<?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
EN

Stack Overflow用户

发布于 2012-02-08 18:14:02

在fopen之后,添加

代码语言:javascript
复制
header('content-type: audio/mpeg');
or
header('content-type: application/octet-stream');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9191115

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档