是否可以允许视频直接从网站流式传输,但阻止使用 .htaccess 下载视频并将请求发送到 php 文件?
RewriteEngine On
RewriteCond %{REQUEST_URI} \.(mp4|flv|avi)$ [NC]
RewriteRule ^(.*)$ /stream-file.php?filename=$1 [L]
但是为此,我假设我需要编写一个通过 php 进行流式传输的脚本,并且我无法将其传递到 jwplayer 等媒体播放器。
或者,我很好奇如何在这里做这样的网站: http://www.statsdoesntsuck.com/york/2320.html
如果您查看源代码,您会在 html 中找到引用主页上视频的部分
<div style="background-color:#404040; border-radius:5px;">
<div style="width:98%; height:auto; margin-right:auto; margin-left:auto; padding-top:6px">
<script type="text/javascript" src="http://content.bitsontherun.com/players/EwneWxTl-8JZHlp0n.js">
</script>
</div>
</div>
EwneWxTl-8JZHlp0n.js 的内容可以在这里找到 http://content.bitsontherun.com/players/EwneWxTl-8JZHlp0n.js (脚本太长,无法粘贴到此处)。
基本上,我正在寻找一种方法,让查找文件名或位置变得有点困难,但仍然能够对其进行流式传输。它不必是 100% 安全的(我知道这是不可能的),但至少它不应该像 viewsource 那样简单 ---> url.com/file.mp4
任何想法将不胜感激。我也在使用 joomla,所以如果有任何模块/插件能够为我做到这一点,那就太好了 - 尽管我不介意从头开始编写它。
换句话来说,保护文件不被下载(不影响流媒体)并能够成为 DIY 项目而不是付费服务项目的最佳方法是什么。
编辑:1.通过apache寻找解决方案 2.我找到了以下Flowplayer Secure Streaming with Apache
它的问题是 htaccess 不允许我流式传输文件,当我删除它时,它会正常流式传输。如果有人可以帮助我弄清楚我可以做些什么来改变它,那就太好了
我的.htaccess如下:
RewriteEngine on
RewriteRule ^(.*)/(.*)/(.*)$ http://localhost/joomla2/video/video.php?h=$1&t=$2&v=$3
RewriteRule ^$ - [F]
RewriteRule ^[^/]+\.(mov|mp4)$ - [F]
目前显示为“找不到文件”。
最佳答案
是的,这很容易做到。这是我为视频流代理编写的工作脚本 -
ob_start();
**// do any user checks here - authentication / ip restriction / max downloads / whatever**
**// if check fails, return back error message**
**// if check succeeds, proceed with code below**
if( isset($_SERVER['HTTP_RANGE']) )
$opts['http']['header']="Range: ".$_SERVER['HTTP_RANGE'];
**// to add multiple headers to the final request, do something like
**// $opts['http']['header']="Range: ".$_SERVER['HTTP_RANGE']."\r\nHeader1: value1\r\nHeader2: value2";
$opts['http']['method']= "HEAD";
$conh=stream_context_create($opts);
$opts['http']['method']= "GET";
$cong= stream_context_create($opts);
$out[]= file_get_contents($real_file_location_path_or_url,false,$conh);
$out[]= $http_response_header;
ob_end_clean();
array_map("header",$http_response_header);
readfile($real_file_location_path_or_url,false,$cong);
关于php - .htaccess/php 来流式传输视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18199367/