【问题标题】:scandir fail to open directoryscandir 无法打开目录
【发布时间】:2012-08-06 19:32:45
【问题描述】:

我在使用 scandir() 时遇到问题。我正在尝试在我的云中子域下的页面上显示我的snaps-目录中的文件。

这是我使用的 PHP。

$files = scandir('./snaps');
print_r($files);

这就是错误。

Warning: scandir(./snaps) [function.scandir]: failed to open dir: No such file or directory in /home/u703778423/public_html/cloud/index.php on line 39

Warning: scandir() [function.scandir]: (errno 2): No such file or directory in /home/u703778423/public_html/cloud/index.php on line 39

我不知道还能做什么。

【问题讨论】:

    标签: php


    【解决方案1】:

    您可能会假设,当前工作目录在编写 scandir() 的脚本旁边,而(在许多情况下)不是。

    scandir(__DIR__ . '/snaps');
    

    【讨论】:

      【解决方案2】:

      鉴于该错误,您的 snaps 目录必须具有的绝对路径

      /home/u703778423/public_html/cloud/snaps
      

      确保这是目录的正确位置,并且网络服务器有权访问它。

      【讨论】:

      • 你怎么知道的?没有提到 ./snaps 应该在哪里,但只有 ./snaps 丢失了。
      • @KingCrunch:因为错误信息中指定了脚本的位置,scandir中的路径为./snaps
      • Snaps 直接在 public_html 中。
      • @cody:那么你的水平太低了。请改用../snaps
      • 我明白了:数组 ( [0] => . [1] => .. [2] => 4f17d7.png [3] => 7i4mhm.jpg [4] => 966kfn。 zip [5] => a0d66f.png [6] => bm88g0.zip [7] => d0cg6i.png [8] => error_log [9] => ff9ihn.gif [10] => fmc7e6.zip [11] => ihhkhn.zip [12] => minecraft.exe )
      【解决方案3】:

      首先,您尝试显示一些不会呈现为图像的文件...例如。 (.zip)。

      您是否还确保不尝试显示前两个索引值“.”和“..”?我认为您的这部分代码可能不是问题...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-12-13
        • 2021-05-24
        • 1970-01-01
        • 1970-01-01
        • 2013-01-11
        • 2018-08-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多