PDA

View Full Version : Liệt kê tên các thư mục



phuongngoc
06-08-2005, 06:57
Em muốn liệt kê tên các thư mục con trong một thư mục do mình chỉ định
Bác nào dạy em với

(dùng PHP)

Thanks

hrockvn
06-08-2005, 07:43
Mặc dù chỉ hiển thị các file ảnh nhưng nó cũng hiển thị các thư mục trong đó, có điều các thư mục này trước nó sẽ có hình dấu X vì nó không phải là image


<?php
/*
* This little example prints a sorted directory
* listing, with dirs first and files afterwards.
*/

// Open current directory
$d = ".";
if($handle = opendir("$d")){

// Loop through all files
while(false !== ($file = readdir($handle))){

// Ignore hidden files
if(!preg_match("/^\./", $file)){

// Put dirs in $dirs[] and files in $files[]
if(is_dir($file)){
$dirs[] = $file;
}else{
$files[] = $file;
}
}
}

// Close directory
closedir($handle);

// if $dirs[] exists, sort it and print all elements in it.
if(is_array($dirs)){
sort($dirs);
foreach($dirs as $dir){
echo "<a href=\"$dir/\">$dir/</a><br />\n";
}
}

// if $files[] exists, sort it and print all elements in it.
if(is_array($files)){
sort($files);
foreach($files as $file){
echo "<a href=\"$d/$file\"><img src='$d/$file' border='0'></a> = $file<br />\n";
}
}
}

?>

phuongngoc
06-08-2005, 16:30
mình hơi... ngu nên không hiểu rõ đoạn code này cho lắm

mà mình copy cái code của bạn cho thì thấy nó show tất cả ra : Thư mục, file ảnh lẫn các file khác.

mình muốn đoạn code PHP chỉ show các folder, sub folder, sub của subfolder....
pác nào biết thì chỉ em với :)