doom910730 2017-05-03 06:07
浏览 109

PHP脚本,用于动态生成当前行为中存在的目录,子目录和文件的链接

Below is the php script I found to dynamically generate links to files present in current directory. can anyone of u help me with php script to dynamically generate links to all the directory ,sub-directory and files present in the root directory.

<?php
$dir_open = opendir('.');

while(false !== ($filename = readdir($dir_open))){
    if($filename != "." && $filename != ".."){
        $link = "<a href='./$filename'> $filename </a><br />";
        echo $link;
    }
}

closedir($dir_open);
?>
  • 写回答

3条回答 默认 最新

  • dongye6377 2017-05-03 06:12
    关注

    Try this:

    ** UPDATE ** To show file name instead of the full path

    <?php
    $directory = new \RecursiveDirectoryIterator($path);
    $iterator = new \RecursiveIteratorIterator($directory);
    $files = array();
    foreach ($iterator as $info) {
        echo  '<a href="' . $info->getFilename() . '">' . $info->getFilename() . '</a><br />';    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法