我想要用php实现一个网页获取一个文件夹 E:\avi里所有后缀是avi和pdf文件的路径,然后把超链接放到网页。
文件夹avi可能是在二级或更高的路径,就是可能E:\avi\1.avi E:\1\x\1.avi 我需要
名字.avi路径用相对路径
希望大神可以给源码
php获取文件夹内所有文件
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答
- qqlindexi 2014-12-18 04:55关注
根据多位大神,php获取服务器文件夹所有文件源码
<!doctype html> <html> <head> <meta charset="GB2312"> <title>php</title> <link href="/intranet/css/gong.css" rel="stylesheet" type="text/css"> </head> <body> <?php $path = "."; $ext = ".avi"; //文件后缀名 function get_filetree($path, $ext) { $tree = array(); $temp = glob($path . "/*" . $ext); if($temp) $tree = array_merge($tree, $temp); foreach (glob($path . "/*", GLOB_ONLYDIR) as $dir) { $temp = get_filetree($dir, $ext); if($temp) $tree = array_merge($tree, $temp); } return $tree; } $list = get_filetree($path, $ext); foreach($list as $item) { $fd=substr($item, 1); echo "<a href=\"/php视频教程".$fd.'">'; echo "".$file = basename($item)."</a>"; echo "<br/>"; } ?> </body>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报