PHP创建文件目录

时间:2015-01-30 16:08:15

标签: php

目录查看文件夹+文件夹中的金额

<?php 
    echo '<ul class="DirView"><li><a href="#">Recently Used<span>28</span></a></li>'; 
    $path = "../Desktop/IMG/BananzaNews/";
    $dir = new DirectoryIterator($path); 

    foreach ($dir as $fileinfo) { 
        if ($fileinfo->isDir() && !$fileinfo->isDot()) { 
            $subPath = $path.$fileinfo->getFilename(); 
            $subDir = new DirectoryIterator($subPath); 
            $count = count(glob($subPath. "/*.*")); 

            $SubCount = 0; 
            $subCategory = ''; 

            foreach ($subDir as $subDirPath) { 
                if ($subDirPath->isDir() && !$subDirPath->isDot()) { 
                    $subDirPathDetails = $subPath.'/'.$subDirPath->getFilename(); 
                    $subDirDetails = new DirectoryIterator($subDirPathDetails); 
                    $subDircount = count(glob($subDirPathDetails. "/*.*")); 

                    $SubCount = $SubCount + $subDircount;
                    $subCategory.= '<li><a href="#">'.str_replace('_', ' ', $subDirPath->getFilename()).'<span>'.$subDircount.'</span></a></li>'; 

                } 

            } 
            echo $mainCategory = '<li><a href="#">'.str_replace('_', ' ', $fileinfo->getFilename()).'<span>'.$SubCount.'</span></a><ul class="sub-menu">'; 
            if(!empty($subCategory)){ 
                echo $subCategory; // sub category li*/ 
            } 
            echo '</ul></li>'; 

        } 

    } 
    echo '</ul>'; 

?>

结果

enter image description here

查看 ONE 文件夹

中的文件
<?php
    $files = glob("../Desktop/IMG/BananzaNews/Thumbs/*.*");
    echo '<div class="SwitchPages"><div class="WrapPages">'; //First tab
    $t = 0;
    for ($i=0; $i<count($files); $i++)
    {
        $root = "http://www.rafflebananza.com/";
        $imagePath = str_replace("../", "",$files[$i]);
        $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $imagePath);
        $imageName = str_replace("Desktop/IMG/BananzaNews/Thumbs/", "", $withoutExt);

        if( $i % 8 == 0 ) {
            $t = $t + 1;
            echo '<div id="Page_'.$t.'_Content" class="Pages">'; //hidden class
        }

        echo '<div class="UploadedImgs">
                <div class="ImgName">'.$imageName.'</div>
                <div class="IMG">
                    <img src="'.$root.$imagePath.'" alt="'.$imageName.'" />
                </div>
            </div>';

        if( $i > 0 && $i % 7 == 0 && $i != count($files) - 1 ) {
            echo '</div>';
        }
        if( $i % 7 == 0 && $i == count($files) - 1 ) {
            echo '</div>';
        } else if($i == count($files) - 1 && $i % 7 != 0 ) {
            echo "</div></div>";
        }
    }
    $t = 1;
    echo '<div class="TabSwitcher">';
    for ($i=0; $i<count($files); $i++)
    {
        if( $i % 8 == 0 ) {
            echo '<div class="Tab" id="Page_'.$t.'">'.$t.'</div>';
            $t = $t + 1;
        }
    }
    echo '</div></div>';
?>

这会显示8个文件,并在底部创建一个标签切换器以显示下一个/预览页面

摘要/问题

这对我自己来说是非常先进的,然而现在我通过将我的两个脚本合并为一个单一的脚本来创建更多的选项卡并点击显示里面文件的子文件夹,我现在更加接受了挑战

注意:

最近使用的不是文件夹,这将是数据库读取,请忽略。

0 个答案:

没有答案