如何使用PHP提供.flv文件? [英] How to serve .flv files using PHP?

查看:173
本文介绍了如何使用PHP提供.flv文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个流媒体视频网站。这个想法是客户应该支付会员资格,登录系统,并能够查看视频。我将使用 FlowPlayer 来展示实际视频。

I'm building a streaming video site. The idea is that the customers should pay for a membership, login to the system, and be able to view the videos. I'm going with FlowPlayer for showing the actual videos.

现在的问题是,视频需要公开存储在某处,并且.flv文件的URL需要传递给流动播放器以便能够显示它们。这会产生问题,因为任何人都可以在互联网上查看视频源,下载视频并将其分发。

The problem now is, the videos need to be stored somewhere publically and the url to the .flv files needs to be passed to flowplayer for it to be able to show them. This creates a problem because anyone can do a view source, download the video, and distribute it all across the internet.

我知道有些人使用php通过图像 header()然后他们可以执行以下操作:

I know some people serve images using php by doing an image header() and then they can do something like:

<img src="image.php?userId=1828&img=test.gif" />

php脚本验证用户ID并提供.gif和gif的实际网址是从未透露过。

The php script validates the user ID and serves up the .gif and the actual url of the gif is never revealed.

无论如何使用.flv或其他任何视频格式都可以吗?例如,文件和用户ID传递到PHP脚本,它验证它们,并返回视频?

Is there anyway to do this with .flv or any other video format also? E.g, the file and user ID passed onto the PHP script, it validates them, and returns the video?

推荐答案

你可以设置在您的网络服务器上只能通过PHP访问的包含FLV文件的目录,然后在您的PHP脚本中,您可以像往常一样对用户进行身份验证,只需向浏览器发送一个标题,告诉它期望FLV,然后回显原始FLV数据:

You can set up a directory containing the FLV files on your webserver that can only be accessed by PHP, then in your PHP script you can authenticate the user as usual and simply send a header to the browser telling it to expect an FLV, then echo the raw FLV data:

<?php
// here is where
// you want your
// user authentication

if ($isAuthenticated)
{
  header("Content-type: video/flv");
  echo file_get_contents($pathToFLV);
}
?>

正如Chad Birch所讨论的,这只会阻止人们直接链接到视频 - 你不能以这种方式防止盗版。

As Chad Birch discussed, this will only prevent people from linking directly to the video - you can't prevent piracy this way.

这篇关于如何使用PHP提供.flv文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆