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 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题