如何识别和发送子文件夹的唯一 ID

How to Identify and send a unique id for sub folders

我不知道如何开始,但我想做的是扫描包含视频文件的目录并将 ID 发送到另一个名为 video.php 的 php 以显示视频.但是,当有子文件夹时,我想识别它并将其唯一 ID 发送到 video.php 以执行不同的操作。我不知道如何识别子文件夹。

main.php

$dir = "./media/";
if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $list[] = $file;
        }
    }
    closedir($handle);
}
krsort($list);
foreach($list as $file) {
    $thelist .= '<div class="button"><div class="item">
        <a href="video.php?id='.$file.'">
        <img src="play.png" 
        alt="VIDEO   Thumbnail"style="width:250;height:150;border:0;">
        <span class="caption">'.$file.'</span> </a></div></div>';
}

video.php

<?php
$id = $_GET['id']; 
?>

<video class='center' controls autoplay>
    <source src="./media/<?php echo $id; ?>" type="video/mp4">
    <source src="./media/<?php echo $id; ?>" type="video/ogg">
    Your browser does not support the video tag.
</video>

我不太确定你在问什么,但无论如何我都会试一试。如果我没有提供合适的解决方案,请提供具体反馈。

main.php

$dir="./media/";
if($handle=opendir($dir)){
    while(false!==($file=readdir($handle))){
        if($file!="." && $file!=".."){
            if(is_dir("$dir/$file")){   // <-- I think this is the part you are looking for
                $dirs[]=$file;
            }else{
                $files[]=$file;
            }
        }
    }
    closedir($handle);
}

krsort($files);  // not sure why you want to sort DESC
foreach($files as $file){
    $thelist.="<div class=\"button\"><div class=\"item\"><a href=\"video.php?id=$file\"><img src=\"play.png\" alt=\"VIDEO Thumbnail\" style=\"width:250;height:150;border:0;\"><span class=\"caption\">$file</span>/a></div></div>";
}

krsort($dirs);  // not sure why you want to sort DESC
foreach($dirs as $dir){
    // provide links to video.php with directory id $dir
}

video.php

$fileid=$_GET['fileid'];  // sanitize this
$dirid=$_GET['dirid'];   // sanitize this

if($fileid){
    echo "<video class=\"center\" controls autoplay>";
        echo "<source src=\"./media/$fileid\" type=\"video/mp4\">";
        echo "<source src=\"./media/$fileid\" type=\"video/ogg\">";
        echo "Your browser does not support the video tag.";
    echo "</video>";
}elseif($dirid){
    // do what you like with $dirid
}else{
    // default action when no id is provided
}