我无法将我的视频显示在我的网页上

时间:2018-05-13 15:53:17

标签: php html mysql video

我正在使用php从我的MYSQL数据库加载视频并将其显示在网页上。视频存储为URL以节省数据库空间。每当我加载网页时,我都会获得播放视频的控件,仅此而已。我如何让视频出现?

height: auto;

3 个答案:

答案 0 :(得分:0)

  • <source>代码不需要结束</source>代码。

  • 确保文件包含在从$row['title']返回的路径中。

  • 此外,$row[title]也应更改为$row['title']

    <?php 
    session_start(); 
    $connect = mysqli_connect("localhost", "root", "root", "videodata"); 
    ?> 
    <!DOCTYPE html> 
    <html> 
     <head> 
       <title>Starter Project</title> 
       <meta charset="utf-8"> 
       <title>HTML5 Audio</title> 
     </head> 
     <body> 
     <?php 
      $query = "SELECT * FROM videos"; 
      $result = mysqli_query($connect, $query);
      if(mysqli_num_rows($result) > 0) {
        while($row = mysqli_fetch_array($result)) { 
     ?> 
         <video width="320" height="240" controls> 
          <source src="<?php echo $row['title'];?>" type="video/mp4">
          Your browser does not support the video tag.
         </video> 
      <?php } } ?>
     </body> 
    </html>
    

答案 1 :(得分:0)

除非您有多种类型的视频,否则您可以使用视频标记的 src 属性:

<video width="320" height="240" controls src="<?php echo $row[title]; ?>" type="video/mp4" />

请注意,要播放视频,必须采用浏览器播放的格式,例如 webm ogg

答案 2 :(得分:-1)

<?php
$getVideo = "select * from videos";

$getVideoRes = mysqli_query($con, $getVideo);

$details = mysqli_fetch_assoc($getVideoRes);

$videoUrl = $details['videoUrl'];
?>

<body>
        <video id="lecVideo" width="340" height="200" controls>
        
        <source src="videos/<?php echo $videoUrl;?>" type="video/mp4">
        
        </video>

</body>
相关问题