微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 嵌入flv和swf位于webroot之外

我有一个在webroot之外上传的脚本.通过网站,我然后将用户链接到图像文档等.

因此,对于图像,链接将是:

media.PHP?file=nameoffile.jpg&user=userid&folder=images

然后用它来显示图像:

<img src="media.PHP?file=nameoffile.jpg&user=userid&folder=images" width="100" border="0">

这适用于图像并提供下载文档的链接.

我面临的问题是嵌入,我使用ffmpeg将所有允许的视频类型转换为flv(这些视频经过测试并且运行良好),但是当我尝试嵌入flv视频时,它永远不会工作(它与文件的直接链接一起使用)只是不通过media.PHP).如果可能的话我也想嵌入.swf.

我正在使用jwplayer嵌入(使用文件的直接链接而不是通过media.PHP)

<!-- START OF THE PLAYER EMbedDING TO copY-PASTE --> 
            <object id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="player" width="328" height="200"> 
            <param name="movie" value="player.swf" /> 
            <param name="allowfullscreen" value="true" /> 
            <param name="allowscriptaccess" value="always" /> 
            <param name="flashvars" value="media.PHP?file=nameoffile.flv&user=userid&folder=videos" /> 
            <embed 
                type="application/x-shockwave-flash"
                id="player2"
                name="player2"
                src="player.swf"
                width="328" 
                height="200"
                allowscriptaccess="always" 
                allowfullscreen="true"
                flashvars="file=media.PHP?file=nameoffile.flv&user=userid&folder=videos"
            /> 
            </object> 
            <script type="text/javascript" src="jwplayer.js"></script>
            <!-- END OF THE PLAYER EMbedDING -->

这是media.PHP

$path_parts = pathinfo($_SERVER['REQUEST_URI']);
        $file = basename(urldecode($_GET['file']));
        $user = basename(urldecode($_GET['user']));
        $folder = basename(urldecode($_GET['folder']));
        $ext = pathinfo($file,PATHINFO_EXTENSION);

        $fileDir = 'pathoutsidewebroot';
        $filePath = $fileDir . $file;

        switch(
        $ext) {
            case "flv": $ctype="video/x-flv"; break;
            // adobe
            case "pdf": $ctype="application/pdf"; break;
            // ms office
            case "doc": $ctype="application/msword"; break;
            case "rtf": $ctype="application/rtf"; break;
            case "xls": $ctype="application/vnd.ms-excel"; break;
            case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
            // open office
            case "odt": $ctype="application/vnd.oasis.opendocument.text"; break;
            case "ods": $ctype="application/vnd.oasis.opendocument.spreadsheet"; break;
            default: $ctype = "application/force-download"; break; 
}

        if(in_array($ext,$valid_formats_vid)){
            if (file_exists($filePath)) {
                header('Content-Type: ' . mime_content_type($filePath));
                header('Content-Length: ' . filesize($filePath));
                readfile($filePath);
        }
        }

        else if(in_array($ext,$valid_formats_img)) {
            if (file_exists($filePath)) {
                header('Content-Type: ' . mime_content_type($filePath));
                header('Content-Length: ' . filesize($filePath));
                readfile($filePath);
            }
        }
        else if(in_array($ext,$valid_formats_docs)) {
                    if (file_exists($filePath))
                    {
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
            header("Cache-Control: private",false);
            header("Content-Type: $ctype");
            header("Content-disposition: attachment; filename=\"".basename($filePath)."\";");
            header("Content-transfer-encoding: binary");
            header("Content-Length: ".@filesize($filePath));
            set_time_limit(0);
            @readfile($filePath) or die("File not found.");                 }
        }

来自media.PHP的嵌入式标题

Cache-Control:no-store,no-cache,must-revalidate,pre-check=0
Connection:Keep-Alive
Content-disposition:filename=encoded_2012-10-19_22.37.09_1359032866.flv
Content-Length:0
Content-Type:video/x-flv
Date:Thu,24 Jan 2013 16:26:32 GMT
Expires:Thu,19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5,max=88
Pragma:no-cache
Server:Apache/2.2.20 (Ubuntu)
X-Powered-By:PHP/5.3.6-13ubuntu3.8

从直接链接文件(工作的那个)的标题

Accept-Ranges:bytes
Connection:Keep-Alive
Content-Length:2428614
Content-Type:video/x-flv
Date:Thu,24 Jan 2013 16:23:54 GMT
ETag:"26ca3d8-250ec6-4d4087c796500"
Keep-Alive:timeout=5,max=100
Last-Modified:Thu,24 Jan 2013 13:07:00 GMT
Server:Apache/2.2.20 (Ubuntu)

管理通过media.PHP将其更改为此(但仍无法正常工作)

header("Content-Type: $ctype");
            header('Content-Length: ' . filesize($filePath));
            header('Accept-Ranges: bytes');
            $Now = time( );
            $then = gmstrftime("%a,%d %b %Y %H:%M:%s GMT",$Now + 365*86440);
            header("Expires: $then");
            ob_clean();
            flush();
            readfile($filePath);



Accept-Ranges:bytes
Cache-Control:no-store,pre-check=0
Connection:Keep-Alive
Content-Length:2428614
Content-Type:video/x-flv
Date:Thu,24 Jan 2013 16:44:18 GMT
Expires:Fri,24 Jan 2014 20:47:38 GMT
Keep-Alive:timeout=5,max=79
Pragma:no-cache
Server:Apache/2.2.20 (Ubuntu)
X-Powered-By:PHP/5.3.6-13ubuntu3.8

解决方法

问题出在这里

flashvars="file=media.PHP?file=nameoffile.flv&user=userid&folder=videos"

flashvars接收查询字符串,因此将其解释为

file   : media.PHP?file=nameoffile.flv
user   : userid
folder : videos

你需要urlencode文件参数:

flashvars="file=media.PHP?file=nameoffile.flv&amp;user=userid&amp;folder=videos"

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐