qqlindexi 2014-12-12 08:31 采纳率: 100%
浏览 2725
已采纳

php获取文件夹内所有文件

我想要用php实现一个网页获取一个文件夹 E:\avi里所有后缀是avi和pdf文件的路径,然后把超链接放到网页。
文件夹avi可能是在二级或更高的路径,就是可能E:\avi\1.avi E:\1\x\1.avi 我需要
名字.avi路径用相对路径
希望大神可以给源码

  • 写回答

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>
    

    显示
    php介绍.avi
    php基础.avi

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗