PHP scandir of an url

有些话、适合烂在心里 提交于 2019-12-18 07:23:16

问题


How can I use scandir with an URL. Now it looks like PHP doesn't see the URL as an URL. Is there a way to use an URL in scandir?

<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>

回答1:


This is not possible. scandir() and many other file operations only work local.

If you want to get a list of files on a remote server then you need a script/API on the server that will return that file list.

Just imagine what would happen if you could read all files and directories on a remote machine? Security would be realy compromised.




回答2:


Scandir works perfectly for local directory.

scandir — List files and directories inside the specified path

But you can't get list of files onto server, because in many cases urls are not directly mapping on files (e.g., location command of nginx webserver). Also webservers usually block possibility of getting list files for directories (see this settings for apache)



来源:https://stackoverflow.com/questions/35840274/php-scandir-of-an-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!