【问题标题】:Index Listing and Sorting Files and Folders exclude PHP索引列表和排序文件和文件夹不包括 PHP
【发布时间】:2017-03-27 07:49:20
【问题描述】:

我是刚开始我的编程工作的新手,我已经需要帮助了! :) 好吧,我希望我的脚本首先显示文件夹,然后显示文件,所以像文件夹这样的文件优先级更高,然后是最后。这是脚本

<?php
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle)))
{
    if ($file != "." && $file != ".." && !preg_match('/\.php$/i', $file) && !preg_match('/robots.txt$/i', $file))
    {
        $thelist .= '<LI><a href="'.$file.'">'.$file.'</a>';
    }
}
closedir($handle);
}
?>

【问题讨论】:

    标签: php file directory


    【解决方案1】:

    这是我的解决方案,如下所示:

    黑色方块只是私人物品。

    这是我的代码

    <!DOCTYPE html>
    <html>
    <head>
        <title>Index of</title>
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <body>
    <table>
    <tr>
    <?php 
        $dir = scandir("./");
        $icon = "http://megaicons.net/static/img/icons_sizes/8/178/512/very-basic-file-icon.png";
        foreach ($dir as $key => $elem) {
            switch (pathinfo($elem,PATHINFO_EXTENSION)) {
                case 'php':
                    $icon = "https://freeiconshop.com/wp-content/uploads/edd/php-outline.png";
                    break;
                case 'html':
                    $icon = "https://image.freepik.com/free-icon/html-file-with-code-symbol_318-45756.jpg";
                    break;
                case 'css':
                    $icon = "https://image.freepik.com/free-icon/css-file-format-symbol_318-45329.jpg";
                    break;
                default:
                    $icon = 'https://1001freedownloads.s3.amazonaws.com/icon/thumb/335424/Very-Basic-Opened-Folder-icon.png';
                    break;
            }
    
            if($key % 5 == 0) {
                echo "</tr><tr>";
            }
    
            if(pathinfo($elem,PATHINFO_EXTENSION) != 'php') {
                echo "<td><a href='$elem'><img src='$icon' height='100px' width='100px'/>$elem</a></td>";
            }
        }
    ?>
    </tr>
    </table>
    </body>
    </html>
    

    【讨论】:

    • 是的,这就是我需要的,如何添加代码以排除要显示的 php 文件?
    • 如果扩展名是php,不要echoif($ext != "php") echo
    • 嗯奇怪不起作用它仍然显示目录中的php文件。
    • 它说我的错误并且不加载我认为我做错了什么。它显示了 php,因为我的服务器无法更新文件。你可以发布代码吗?谢谢
    • 但是 HTTP 500 错误是一个服务器错误,这是一个不同的问题。
    猜你喜欢
    • 2011-12-22
    • 1970-01-01
    • 1970-01-01
    • 2019-08-15
    • 1970-01-01
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    相关资源
    最近更新 更多