0

所以我有一个初始代码,可以在 30 个完美运行的图像之间旋转。我现在正在尝试调整代码以在 30 个视频之间旋转,但由于视频未加载到我的主页中,因此无法使其正常工作。我错过了一些我必须改变的东西吗?代码如下。谢谢

主页

$key = rand(1,30); 
<video width="320" height="240" controls autoplay>
    <source src="rotate.php?num=<?php echo $key; ?>

旋转.php

    <?php
    $folder = './videos';
    $extList = array();
    $extList['mp4'] = 'video/mp4';

$img = null;

if (substr($folder,-1) != '/') {
    $folder = $folder.'/';
}
$imageNumber = 3;

if(isset($_GET['num'])){
    $imageNumber = $_GET['num'];
}
if (isset($_GET['img'])) {
    $imageInfo = pathinfo($_GET['img']);
    if (
        isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
        file_exists( $folder.$imageInfo['basename'] )
    ) {
        $img = $folder.$imageInfo['basename'];
    }
} else {
    $fileList = array();
    $handle = opendir($folder);
    while ( false !== ( $file = readdir($handle) ) ) {
        $file_info = pathinfo($file);
        if (
            isset( $extList[ strtolower( $file_info['extension'] ) ] )
        ) {
            $fileList[] = $file;
        }
    }
    closedir($handle);

    if (count($fileList) > 0) {

        $img = $folder.$fileList[$imageNumber];
    }
}

if ($img!=null) {
    $imageInfo = pathinfo($img);
    $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
    header ($contentType);
    readfile($img);
} else {
    if ( function_exists('imagecreate') ) {
        header ("Content-type: video/mp4");
        $im = @imagecreate (100, 100)
            or die ("Cannot initialize new GD image stream");
        $background_color = imagecolorallocate ($im, 255, 255, 255);
        $text_color = imagecolorallocate ($im, 0,0,0);
        imagestring ($im, 2, 5, 5,  "IMAGE ERROR", $text_color);
        imagepng ($im);
        imagedestroy($im);
    }
}

?>
4

0 回答 0