我能够检索名称,但为什么我不能在嵌入位置显示整个视频?
这是我正在处理的整个PHP文件。
第一个框主要是关于将视频上传到目录和数据库。
我实际上只是因为视频没有出现而对第二个框有问题。
<?php
include 'connect.php'; //include the php file into this php file
?>
<div id="box">
<form method='post' enctype="multipart/form-data">
<?php
if(isset($_FILES['video'])){
$name = $_FILES['video']['name'];
$type = explode('.', $name);
$type = end($type);
$size = $_FILES['video']['name'];
$random_name = rand();
$tmp = $_FILES['video']['tmp_name'];
if($type != 'mp4' && $type != 'mp4' && $type != 'wmv'){
$message = "Video Format Not Supported!";
}
else {
move_uploaded_file($tmp, 'videos/'.$random_name.'.'.$type);
mysqli_query($db, "INSERT INTO videos (id, name, url)
VALUE ('', '$name', '$random_name.$type')");
$message = "Successfully Uploaded!";
}
echo "$message";
}
?>
Select Video : <br/>
<input type='file' name="video" />
<br/><br/>
<input type="submit" value="Upload" />
</form>
</div>
<div id="box">
<?php
$query = mysqli_query($db, "SELECT `id`, `name`, `url` FROM videos");
while($run = mysqli_fetch_array($query)){
$video_id = $run['id'];
$video_name = $run['name'];
$video_url = $run['url'];
?>
<?php
echo $video_name;
?>
<?php
$video = $_GET['video'];
echo "<embed src=`$video` width='560' height='315'></embed>" ;
?>
<?php
}
?>
</div>
答案 0 :(得分:2)
HTML中有反引号而不是引号。将它们更改为单引号或双引号,例如:
echo "<embed src='$video' width='560' height='315'></embed>" ;
^ ^
答案 1 :(得分:1)
你应该
if (isset($_GET['video'])) {
$video = $_GET['video'];
echo '<embed src="'.$video.'" width="560" height="315"></embed>';
}
因此,如果没有输入视频ID,人们就无法访问该页面
答案 2 :(得分:0)
尝试这种方式,它将要求您更改数据库。但应该工作。只需阅读我使用它的注释说明。
<div id="box">
<?php
if (isset($_GET['video'])) {
$video = $_GET['video'];
$query = mysql_query("SELECT * FROM `videos` WHERE `id`='$video'");
$count = mysql_num_rows($query);
if ($count!=0) {
$row = mysql_fetch_assoc($query);
$video_id = $row['id'];
$video_name = $row['name'];
$video_url = $row['url'];
echo $video_name;
echo '<embed src="'.$video_url.'" height="315px" width="560px">';
//echp <video height="315px" width="560px" controls><source src="movie.mp4" type="video/mp4"></video>
//Use the above code if you want a html5 video player.
} else {
echo 'Video does not exist!';
}
} else {
echo 'Please enter a video id!';
}
/*
How to use it:
Create a database called "videos"
Insert the following three columns:
id = varchar(225) as `primary_key`
name = varchar(225);
url = varchar(225);
To insert a video, you will need to create
a random id for the video and insert it
into the mysql database. Example
$rand = rand(111111111,999999999);
$id = md5($rand);
//example $id = 3174143713413051830531
$name = "Random video name";
$url = "http:/localhost/websitename/videos/nameofvideo.mp4";
$query = mysql_query("INSERT INTO `videos` VALUES ('$id','$name','$url')");
Then to select the video you will go to a page
video.php?video=[video id here];
video.php?video=3174143713413051830531
then the php will select the url for the video
id = 3174143713413051830531
and it will play that video.
example: video_url would be http://localhost/websitename/videos/nameofvideo.mp4
If you have any further questions,
feel free to ask me. Thanks
*/
?>
</div>
希望这有效。谢谢!