php 抓取目錄名稱 / php 抓取資料夾名稱

這是一個可以把目錄內的目錄顯示出來,之前把教學頁,整理成在一個目錄,

後點連結就進入目錄index.htm觀看,很久前就想用成這樣,最近有空用好了




主要代碼如下

<?php
$zdir = './';
$zhost = $_SERVER['HTTP_HOST'];
if (is_dir($zdir)) {
if ($zdh = opendir($zdir)) {
$zchbw01 = 1;
while (($zfile = readdir($zdh)) !== false) {
if ($zfile != "." && $zfile != ".." && filetype($zdir.$zfile) == 'dir') {
if($zchbw01 == 1){
echo '<div class="b001"><a href="http://'.$zhost.'/a/'.$zfile.'/index.htm"><strong> '.$zfile.'/</strong></a></div>';
$zchbw01 = 0;
}else{
echo '<div class="w001"><a href="http://'.$zhost.'/a/'.$zfile.'/index.htm"><strong> '.$zfile.'/</strong></a></div>';
$zchbw01 = 1;
}
}
}
closedir($zdh);
}
}
?>

當然也可以抓取檔名,只是我要目錄名稱,所以在 filetype 只比對 dir

該程序下載,自選其一


asuswebstoragesync.hamicloud.netonedrive.live.comdrive.google.com


7-zip 解壓後,再用 文字編輯器 打開,參考圖




Thank you for reading

沒有留言:

發佈留言

由於經常被灌水, 所以您再發表留言之後, 需要耐心的等待博客主之審核, 於審核過後才會公開您的留言, 因此請您不要重複的留言, 謝謝您的留言
Hello my friend, I have no money, My blog is super chill, Please do not screw me in the replies at the bottom of the article, thank you very much