doumu1873 2011-06-13 22:07
浏览 32
已采纳

流视频php

I am trying to get my php video handler file to serve up videos and am testing it on the file handler page itself without luck.

Weird behaviour: A window just pops up asking me if I want to download the file, even if I delete the readfile(). If I change video/x-flv to video/flv then a player loads in my window but the file does not play. Also if I take away that header all together my browser crashes.

I figured this script should place the video in the browser at the least and have it be playable in the browser if I am testing the file directly with the browser. The file path is correct after the query... Also the file is outside of my web directory but I don't think that should matter because I can serve images outside the directory successfully using a similar script. Anyone have any ideas?

$sql="SELECT file_name FROM video WHERE vid_id=?";
$stmt=$conn->prepare($sql);
$result=$stmt->execute(array($ID));

while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$file_name = $row['file_name'].".flv";
}

$path="/home/g/Desktop/processed/".$file_name."";


//check if image is readible and type
if (is_readable($path)) {
header('Content-Length: '.filesize($path)); // provide file size
header("Expires: -1");
header('Content-Type: video/x-flv');

$content=readfile($path);


}
else {
error_log("Can't serve video: $file_name");
}
  • 写回答

2条回答 默认 最新

  • double0201 2011-06-13 22:34
    关注

    Streaming doesn't work like that.
    To have a proper streaming you need to use a Player like: http://flowplayer.org/

    If you just send the content of the video, the browser will pop up the save dialog

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用