0

我正在尝试在网页中包含 avi 视频。为了安全起见,视频保存在 webroot 文件夹之外,并使用 PHP 动态加载(请参阅下面的完整代码)。

示例完整路径为“/Users/me/project/1/video/test1.avi”;

该页面遇到一个奇怪的错误。我使用以下语句构建文件的路径:

$pic = $CFG->dataroot."/".$COURT->id."/".$preview;

//($CFG->dataroot = '/Users/me/project')
//($COURT->id = 1 - a number representing the folder name.)
//($preview = 'video/test1.avi' - or the location of image/video)

这适用于图像,但无法加载仅显示视频控件和“正在加载...”的视频

编辑:我已经回显了 $COURT->id 并且变量 1 被正确传递

如果我更改代码并通过删除 $COURT->id 直接指定目录,则它适用于视频和图像。

$pic = $CFG->dataroot."/1/".$preview;  //- works

任何想法为什么会这样?

在此先感谢史蒂夫

(我正在使用 Apache 和 Safari 在 Mac 上进行测试。)

 

完整代码:

<?php
$preview = $_GET['preview'];

//works with images but not video
//$pic = $CFG->dataroot."/".$COURT->id."/".$preview;

//works but the folder '1' needs to dynamic i.e. var $COURT->id
$pic = $CFG->dataroot."/1/".$preview;

if ( isset($_GET['preview']) ) {
    if (file_exists($pic) && is_readable($pic)) {
        // get the filename extension
        $ext = substr($pic, -3);
        // set the MIME type
        switch ($ext) {
        case 'jpg':
            $mime = 'image/jpeg';
            break;
        case 'gif':
            $mime = 'image/gif';
            break;
        case 'png':
            $mime = 'image/png';
            break;
        case 'avi':
            $mime = 'video/avi'; //$mime = 'video/x-msvideo';
            break;
        case 'doc':
            $mime = 'application/msword';
            break;
        case 'tif':
            $mime = 'image/tiff';
            break;
        default:
            $mime = false;
    }
    // if a valid MIME type exists, display the image
    // by sending appropriate headers and streaming the file
    if ($mime) {
        header('Content-type: '.$mime);
        header('Content-length: '.filesize($pic));
        $file = @ fopen($pic, 'rb');
        if ($file) {
            fpassthru($file);
            exit;
        }
    }
}

}

4

1 回答 1

0

Obviously, when images are sent as $preview (on page before where link to preview is), courtid is sent dynamically to next page, and its OK.

But when video is sent as $preview - courtid its not se(n)t.

Why not, we cannot see in these codes, but codes before, ones that triggers this (play) function.

Try to echo courtid on a page where video should play to check out if it is set as 1 and thats it.

I simply cannot find any other logical solution.

于 2013-09-05T23:52:46.923 回答