dsmvqp3124 2018-05-12 14:27
浏览 71


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.

$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


    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.


    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 NeRF的代码复现以及人工智能入门
  • ¥15 centos如何做一个可以让ikuai连接的openvpn
  • ¥15 Protege 中的Entities下面的界面删除了如何复原
  • ¥15 scrapy爬虫求帮
  • ¥15 imageEnView绘图问题
  • ¥15 关于#python#的问题:您好可以加您一下联系方式吗,在复现的时候确实有点问题难以解决
  • ¥15 联想电脑重装系统时无法发现硬盘
  • ¥15 MATLAB与UR10e实体机械臂建立通讯
  • ¥15 c++题需要快一点不用opencv
  • ¥15 关于#java#的问题:想要咨询Flowable流程引擎框架的问题