dragon8837 2012-08-14 01:28
浏览 35

如何使用PHP通过HTTP打开大文件,然后在浏览器中显示以供查看?

I have a tomcat server (Server A) which has a ton of progressively streaming encoded mp4 video and mp3 audio files and is on a private network. I also have a web server (Server B) running Apache 2 and PHP which is on the private network and has a public facing interface. Server B manages application ACL.

I want a client (say a browser) to be able to go to a specific url on Server B's public interface, and be able to download, (listen or view in a player) the media from the private server. At the moment, on server B, I have tried the following:

<?php
$handler = fopen('http://server_a/path/to/file.mp4', 'r');
header('Content-type: video/mp4');
while (!feof($handler)) {
    print fread($handler, 8192);
}
exit;

and

<?php
$handler = fopen('http://server_a/path/to/file.mp4', 'r');
header('Content-type: video/mp4');
print stream_get_contents($handler);
exit;

and

<?php
$handler = fopen('http://server_a/path/to/file.mp4', 'r');
header('Content-type: video/mp4');
fpassthru($handler);
exit;

All of which PHP will either run out of memory or the client (browser) will download the entire file before even beginning to play. Am I going the wrong way about this? Any ideas on what I could be doing wrong?

  • 写回答

3条回答 默认 最新

  • 普通网友 2012-08-14 01:31
    关注

    No, that's the way it works. Basically your php is showing the file as a file. Your PHP script is going from "I'm not an HTML file, I'm an MP4 File, and here's my contents". PHP is not what you want for streaming

    Why not try using HTML5 Video or Audio, pointing to your PHP script?

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c