今天想加个功能,就是生成html地图提供百度蜘蛛抓取,就要用到php获取目录文件夹下的内容调取。所以放上代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>常识模块地图</title> </head> <body> <?php $new_array = array(); function loopDir($dir,&$new_array) { $handle = opendir($dir); while(($file = readdir($handle))!== false ){ if ($file != '.' && $file != '..'){ if (filetype($dir.'/'.$file) != 'dir'){ $fileurl="http://www.bkbook.net/changshi/html/".$file; echo "<a href='".$fileurl."'>".$file."</a> "; } if (filetype($dir.'/'.$file) == 'dir'){ loopDir($file,$new_array); } } } } $dir = './'; loopDir($dir,$new_array); ?> </body> </html>
这样就成功了:http://www.bkbook.net/changshi/html/
标签:文件夹,file,array,php,目录,dir From: https://www.cnblogs.com/68xi/p/16935163.html