dongqian7545 2011-10-29 17:16
浏览 135
已采纳

列出文件夹中的所有项目

I want to write a php script, which lists all the items in the folder, where the php script is located/in the folder where it was started (except index.php)...

I got 2 Problems

1. ATM it is only listing the items in the folder "foobar"<br/>
2. It is not creating a new `<li>` Tag for every new items<br/>

This is my code so far...

<?php

$folder = openDir("foobar");

while ($file = readDir($folder)) {

 if ($file != "." && $file != "..") {

  echo "<!DOCTYPE HTML>
<html>
<head>
<title>nothing</title>
<link href='http://fonts.googleapis.com/css?family=Raleway:100' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Vollkorn:700' rel='stylesheet' type='text/css'>
<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />
</head>
<body>

<div id=\"title\">
<h1>nothing</h1>
</div>

<div id=\"main\">
<ul>
    <li><a href=\"foobar/$file\">$file</a></li>
</ul>
</div>

</body>
</html>";
 }
}

closeDir($folder);
?>
  • 写回答

2条回答 默认 最新

  • dqf35839 2011-10-29 17:23
    关注
    <!DOCTYPE HTML>
    <html>
    <head>
        <title>nothing</title>
        <link href='http://fonts.googleapis.com/css?family=Raleway:100' rel='stylesheet' type='text/css' />
        <link href='http://fonts.googleapis.com/css?family=Vollkorn:700' rel='stylesheet' type='text/css' />
        <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
        <div id="title">
            <h1>nothing</h1>
        </div>
    
        <div id="main">
            <ul>
    <?php
    $folder = openDir(__DIR__);
    while ($file = readDir($folder)) {
        if ($file != "." && $file != ".." && $file != "index.php" && $file != "style.css") {
            echo "<li><a href=\"foobar/$file\">$file</a></li>";
        }
    }
    ?>
            </ul>
        </div>
    </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码