以前面试时经常会遇到遍历目录文件遍历问题,之前都没人在对付过,先正是研究下
关键函数:opendir(), readdir(), is_dir()
function list_jpg($dir) {
if(!($handel=opendir($dir))) {
echo '目录不正确';
return;
}
while($file=readdir($handel)) {
if(($file=='.') || ($file=='..')) continue;
$fullpath = $dir.DIRECTORY_SEPARATOR.$file;
if(is_dir($fullpath)) {
list_jpg($fullpath);
}
$pathinfo = pathinfo($file);
if(strtolower($pathinfo['extension'])=='jpg') {
echo $fullpath.nl2br("\n");
}
}
}