2017-03-27 87 views
0

我剛開始我的編程工作,並且已經需要幫助,在這裏我非常非常新! :)好吧,我希望我的腳本先顯示文件夾,然後再像文件夾那樣有更優先的文件先上後下。這裏是腳本索引列表和排序文件和文件夾排除PHP

<?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

這是我的解決方案,它看起來是這樣的:

enter image description here

黑方塊只是私人的事情。

這裏是我的代碼

<!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> 
+0

是啊這就是我所需要的,如何我可以添加代碼excluse PHP文件中顯示? – eXme

+0

如果擴展名是'php'則不要'echo'。 'if($ ext!=「php」)echo' – WasteD

+0

非常感謝我的英雄xD – eXme