dsmvqp3124 2018-05-12 14:27
浏览 71
已采纳

使用PHP变量HTML嵌入视频不起作用

I'm trying to display all videos a webpage using the following code, I've gotten as far as being able to iterate over the files, printing the file names and embedding a video. However the videos are greyed out and don't work, I suspect I did something wrong with using $filename in the code.

<?php
$dir = new DirectoryIterator(dirname(__FILE__));
foreach ($dir as $filename) {
    if (!$filename->isDot()) {

        if ($filename != "index.php" and $filename != "error_log") {

            echo $filename, "<br>"; 

            echo '<video width="400" controls="controls" preload="metadata">
            <source src=$filename type="video/mp4"></video>';

            echo "<br><br>";
        }

    }
}
?>

This is how it shows up:

enter image description here

enter image description here

  • 写回答

3条回答 默认 最新

  • droxy80248 2018-05-12 14:31
    关注

    Hi

    You are echo $filename like a string, not a PHP variable.

    Remember, if echo with single quotes ' all inside it will echo like string and echo with double quotes " will echo PHP variables reading their value. Informations about strings in PHP are nicley explained e.g. here .

    You can change your piece of code witch echo HTML video to:

    echo '<video width="400" controls="controls" preload="metadata"><source src="' . $filename . '" type="video/mp4"></video>';
    

    Note that there were also missing double quotes for HTML video tag src property and I added them in code above.

    Cheers

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题