【问题标题】:Reading a directory with php用php读取目录
【发布时间】:2014-01-02 18:48:55
【问题描述】:

这曾经位于http://elijahhoffman.com/index.php?q=editorial&z=one,现在位于http://elijahhoffman.com/editorial/one

用于读取“galleries/editorial_i”的文件夹路径;但它不起作用,我认为是因为新的路径位置......所以我将完整的 url 附加到路径中,它仍然不起作用......想法?

<?php

    $folder = 'http://elijahhoffman.com/galleries/editorial_i/';
    $handle = opendir($folder);
    while (false !== ($file = readdir($handle))) {
       if ($file != '.' && $file != '..') {
          $files[] = $file;
       }
    }
    closedir($handle);
    sort($files);
    foreach ($files as $file) {
      print <<<EOF
      <img src="{$folder}/{$file}" class="imgfullmargin" alt="{$file}"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      EOF;
    }
 ?>

【问题讨论】:

  • $folder 的值不是一个目录,它是一个 url,可能不支持目录列表:据我所知,只有 file:// 和 ftp://支持这个,不是 http://
  • 根据specs,“4.3.0 路径也可以是任何支持目录列表的 URL,但是 PHP 4 中只有 file:// URL 包装器支持。”
  • php.net/opendir#refsect1-function.opendir-changelog,如您所见,您无法使用 http://,只能使用 file:// 和 ftp://

标签: php readdir opendir


【解决方案1】:

传递给opendir的参数应该是路径,而不是url:

$folder = './galleries/editorial_i/';
$handle = opendir($folder);
...

【讨论】:

  • 明白了。全部固定!很简单:)
猜你喜欢
  • 1970-01-01
  • 2011-01-11
  • 1970-01-01
  • 1970-01-01
  • 2013-09-04
  • 2018-03-07
  • 1970-01-01
  • 2011-01-29
相关资源
最近更新 更多