【问题标题】:PHP scandir of an urlurl的PHP scandir
【发布时间】:2016-03-07 09:34:10
【问题描述】:

如何使用带有 URL 的 scandir。现在看起来 PHP 没有将 URL 视为 URL。有没有办法在 scandir 中使用 URL?

<form action="new_exercise.php?id=<?php echo $new_id; ?>" method="post">
        <input class="" type="text" name="name_exe" required placeholder="Project naam">
        <select name="audio" required>
          <option></option>
          <?php
          $path = 'URL comes here';
          $results = scandir($path);
          foreach ($results as $result) {
              if ($result === '.' or $result === '..') continue;

              if (is_dir($path . '/' . $result)) {
                  echo "<option>" . $result . "</option>";
              }
          }
          ?>
        <select>
        <input class="btn-success" type="submit" name="submit" value="Maak nieuwe opdracht">
    </form>

【问题讨论】:

  • 我当然希望scandir不允许这样做
  • 我很确定你不能用 url 做到这一点。 scandir 函数接受相对或绝对的目录路径,但您不能将 URL 传递给此函数。这是不可能的。

标签: php url scandir


【解决方案1】:

这是不可能的。 scandir() 和许多其他文件操作只能在本地工作。

如果您想获取远程服务器上的文件列表,那么您需要服务器上的脚本/API 来返回该文件列表。

想象一下如果你可以读取远程机器上的所有文件和目录会发生什么?安全性真的会受到威胁。

【讨论】:

    【解决方案2】:

    Scandir 非常适合本地目录。

    scandir — 列出指定路径内的文件和目录

    但是您无法将文件列表获取到服务器上,因为在许多情况下,url 并不直接映射到文件(例如,nginx webserverlocation 命令)。此外,网络服务器通常会阻止获取目录列表文件的可能性(请参阅apache 的此设置)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-15
      • 2011-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多