简体   繁体   English

如何在php中找到并列出所有视频文件和缩略图?

[英]How can you find and list all video files and thumbnails in php?

I have a linux server filled with mp4/m4v videos (400+ and growing) and would like to create a listing of all the videos. 我有一个充满mp4 / m4v视频的Linux服务器(400+并且还在增长),并希望创建所有视频​​的列表。 Somewhat similar to HBO Go. 与HBO Go有些相似。

An example of what I'm trying to accomplish is scanning the current directory and listing all the video mp4/m4v files with a direct link embedded into an image. 我想要完成的一个例子是扫描当前目录并列出所有视频mp4 / m4v文件,并在图像中嵌入直接链接。

Example of the files: 文件示例:

Dir1
   CurrentDirectoryLister.php
   Halloween (2018).mv4
   Halloween (2018).png
   Pacific Rim.mp4
   Pacific Rim.png
Dir2
   CurrentDirectoryLister.php
   NewMovie Here.mp4
   NewMovie Here.png

So, the user will click a link to Dir1 and which will open CurrentDirectoryLister.php and be provided with the images "Pacific Rim.png" and "Halloween (2018).png". 因此,用户将单击指向Dir1的链接,该链接将打开CurrentDirectoryLister.php,并提供图像“Pacific Rim.png”和“Halloween(2018).png”。 When they click an image it takes them to the movie page "Dir1/Pacific Rim.mp4/" 当他们点击图像时,会将他们带到电影页面“Dir1 / Pacific Rim.mp4 /”

To do this I set up two separate arrays. 为此,我设置了两个单独的数组。

One containing only photos and one only videos. 一个只包含照片和一个仅包含视频。

All of my files have matching names so $movies[1] and $images[1] (Pacific Rim.mp4 && Pacific Rim.png). 我的所有文件都有匹配的名称,所以$movies[1]$images[1] (Pacific Rim.mp4 && Pacific Rim.png)。

Further explained by another user HERE 由另一个用户进一步说明该处

<?php
$movies = glob('./*.{mp4,m4v}', GLOB_BRACE);
$images = glob('./*.{jpeg,jpg,png}', GLOB_BRACE);
$subtitles = glob('./*.{srt}', GLOB_BRACE); #To be used later.

foreach ($images as $image) {
    $lookup[pathinfo($image, PATHINFO_FILENAME)] = $image;
}

foreach ($movies as $movie) {
    $image = $lookup[pathinfo($movie, PATHINFO_FILENAME)] ?? 'default.jpg';
    echo '<a href="' . $movie . '">
            <img src="' . $image . '" style="width:300px;height:350px;border:0;">
        </a>';
}
?>

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

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