【发布时间】:2015-10-07 12:51:37
【问题描述】:
我有一个包含 MP4 视频的视频文件夹。我的 PHP 代码查看该文件夹并获取一个视频的名称并使用该名称填充 HTML5 video 元素。
$fname = $files[0];
[0]在php中代表第一个MP4视频。如果我将其更改为 [1],它将使用第二个 mp4 视频填充视频标签,如果我将其更改为 [2],它将获得下一个 MP4 视频名称。
这一切都有效,因为我的文件夹中只有 3 个 MP4 视频。但是如果在文件夹中找不到视频,我需要的是重定向。
目前,如果我从文件夹中取出其中一个视频,我会收到一个 php 错误:
注意:未定义的偏移量:C:\xampp\htdocs\video1.php 第 18 行中的 3。
<!DOCTYPE html>
<html>
<head>
<title>Tv Web Video1</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="scripts/jquery.cycle.all.min.js" type="text/javascript"></script>
</head>
<body bgcolor="#A9A9A9">
<div id="wrapper">
<div id="content">
<div>
<?php
$files = glob('videos/*.mp4'); // get all .mp4 files from folder
$fname = $files[0]; // get 1st filename
$ftext = ucwords(str_replace('_', ' ', basename($fname, '.mp4'))); // format text for display
?>
<video id="video" class="box" poster="poster.jpg" preload="metadata" controls muted width="100%"
max-width:500px; height="50%" max-height:500px; autoplay onended="window.location = '/video2.php';">
<source src="<?php echo $fname; ?>"/>
</video>
<div id="infobox" class="box">Video: '<b><?php echo $ftext; ?></b>'</div>
<ul id="playlist" class="box">
</div>
</div>
</body>
</html>
【问题讨论】:
-
At them moment if i take out one of the videos for the folder i get a php error NOTICE: Undefined offset: 3 in C:\xampp\htdocs\video1.php on line 18.好像你没有在localhost上运行它? -
嗨 HawasKaPujaari 不,它在本地主机上