我刚开始编程工作时非常新,已经需要帮助! :)好吧,我希望我的脚本先显示文件夹然后显示文件,这样文件夹就会有更多优先级,然后是最后一个。这是脚本
<?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);
}
?>
答案 0 :(得分:0)
这是我的解决方案,它看起来像这样:
黑色方块只是私人物品。
这是我的代码
<!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>