简体   繁体   English

PHP scandir查找视频文件,不包含子目录

[英]PHP scandir to find video files and not include subdirectories

I am trying to scan a directory and find all of the files, but I do not want to list the sub-directories. 我正在尝试扫描目录并找到所有文件,但是我不想列出子目录。 So what I did so far was this: 所以到目前为止,我所做的是:

$directory = realpath(APPPATH.'../uploads/videos');
$videos = array_diff(scandir($directory), array('..', '.'));
foreach ($videos as $video){
    echo $video;
    echo "<br>";
}  

The output of this is: 输出为:

  • Video_10mb.mp4 Video_10mb.mp4
  • Video_20mb.mp4 Video_20mb.mp4
  • Video_5mb.mp4 Video_5mb.mp4
  • poster 海报
  • thumbs 拇指
  • tmp tmp

I only want to list the files not the sub-directories. 我只想列出文件而不是子目录。 Like this: 像这样:

  • Video_10mb.mp4 Video_10mb.mp4
  • Video_20mb.mp4 Video_20mb.mp4
  • Video_5mb.mp4 Video_5mb.mp4

How do I only show the video files? 如何只显示视频文件?

You can try this way using glob() to find all the files in the directory /path/to/your/directory with a .mp4 file extension: 您可以尝试使用glob()以这种方式尝试在目录/ path / to / your /目录中以.mp4文件扩展名查找所有文件:

foreach (glob("/path/to/your/directory/*.mp4") as $filename) {
    echo "$filename size " . filesize($filename) . "\n";
}

See Example : http://php.net/manual/en/function.glob.php 参见示例http : //php.net/manual/en/function.glob.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM