用php读取目录

时间:2014-01-02 18:48:56

标签: php readdir opendir

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

用于读取'gallery / 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;
    }
 ?>

1 个答案:

答案 0 :(得分:0)

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

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