내용으로 건너뛰기
adminschool.net wiki
사용자 도구
로그인
사이트 도구
검색
도구
문서 보기
이전 판
역링크
최근 바뀜
미디어 관리자
사이트맵
로그인
>
최근 바뀜
미디어 관리자
사이트맵
추적:
•
toc
•
6week_1
•
mobile_web
•
tableindexsinglebody
•
bash
•
2week_1
•
reference
•
install
•
backuprecovery
develop:php:filelist
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
====== 디렉토리에서 리스트 읽어오기 ====== ===== 함수를 이용한 리스트 ===== <code php> <html> <body> <?php function get_dirlist($start_dir) { exec("ls -R $start_dir",$f_list); $dir_str = $start_dir; $filelist[0] = $start_dir; $i = 1; for ($count=0; $count<count($f_list); $count++) { if ($f_list[$count] == "") { continue; } if (substr($f_list[$count],strlen($f_list[$count])-1,1) == ":") { $dir_str = substr($f_list[$count],0,strlen($f_list[$count])-1); $filelist[$i] = $dir_str; $i++; } else { $file_str = "$dir_str/$f_list[$count]"; if (is_file($file_str)) { $filelist[$i] = $file_str; $i++; } } } return $filelist; } ?> <? $start_dir ="."; $filelist = get_dirlist($start_dir); for ($c=0; $c<count($filelist); $c++) { echo iconv("EUC-KR","UTF-8",$filelist[$c]) . "<br>"; } ?> </body> </html> </code> <code php> <? function getFileList($dir) { # array to hold return value $retval = array(); # add trailing slash if missing if(substr($dir, -1) != "/") $dir .= "/"; # open pointer to directory and read list of files $d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading"); while(false !== ($entry = $d->read())) { # skip hidden files if($entry[0] == ".") continue; if(is_dir("$dir$entry")) { $retval[] = array( "name" => "$dir$entry/", "type" => filetype("$dir$entry"), "size" => 0, "lastmod" => filemtime("$dir$entry") ); } elseif(is_readable("$dir$entry")) { $retval[] = array( "name" => "$dir$entry", "type" => mime_content_type("$dir$entry"), "size" => filesize("$dir$entry"), "lastmod" => filemtime("$dir$entry") ); } } $d->close(); return $retval; } $dirlist = getFileList("./"); echo "<table>\n"; echo "<tr><th>Name</th><th>Type</th><th>Size</th><th>Last Mod.</th></tr>\n"; foreach($dirlist as $file) { echo "<tr>\n"; echo "<td>{$file['name']}</td>\n"; //echo "<td>".iconv("EUC-KR","UTF-8",$file['name'])."</td>\n"; //$filename = iconv("EUC-KR","UTF-8",$file['name']); //echo "<td><a href='$filename'>$filename</a></td>\n"; echo "<td>{$file['type']}</td>\n"; echo "<td>{$file['size']}</td>\n"; echo "<td>" . date("r", $file['lastmod']) . "</td>\n"; echo "</tr>\n"; } echo "</table>\n\n"; ?> </code> ===== 다운로드 받기 ===== - http://www.evoluted.net/community/code/directorylisting.php {{develop:php:dirlistingv2.zip|}}
develop/php/filelist.txt
· 마지막으로 수정됨: 2007/10/07 15:37 저자
starlits
문서 도구
문서 보기
이전 판
역링크
맨 위로