【问题标题】:php Scandir() errors because of me or wampserver?php Scandir() 错误是因为我还是 wampserver?
【发布时间】:2014-02-18 10:32:03
【问题描述】:

当我使用这段代码(如下)时,它给了我 3 个错误。是我还是 Wampserver?我该怎么办?

<?php
$dir = "/gallery/";
$o = scandir($dir);

print_r($o);
?>

错误 1:

Warning: scandir(/gallery/,/gallery/) [<a href='function.scandir'>function.scandir</a>]: The system cannot find the file specified. (code: 2) in C:\wamp\www\random1\index.php on line 3

错误 2:

Warning: scandir(/gallery/) [<a href='function.scandir'>function.scandir</a>]: failed to open dir: No such file or directory in C:\wamp\www\random1\index.php on line 3

错误 3:

Warning: scandir() [<a href='function.scandir'>function.scandir</a>]: (errno 2): No such file or directory in C:\wamp\www\random1\index.php on line 3

【问题讨论】:

  • 删除画廊前面的第一个/。
  • 也可以去掉最后一个/

标签: php html wamp wampserver scandir


【解决方案1】:

您正在搜索 /gallery/ 目录。第一个 / 表示它将从根开始搜索。删除它将使其相对。所以改变

$dir = "/gallery/";

$dir = "gallery";

【讨论】:

    【解决方案2】:

    您需要更正您的路径。在路径中的任何内容之前使用斜杠将指定C:\wamp 目录。亨奇 $dir = "/gallery";,它将查看C:\wamp

    假设你的目录结构是(在 www\your_project 目录中)

    your_file_being_executed.php
    gallery
        img.jpg
    

    您可以使用$dir = "gallery"; 如果结构是

    some_dir
       your_file_being_executed.php
    gallery
       img.jpg
    

    那么你可以使用$dir = "../gallery";

    您还可以使用__Dir____FILE__ 语言常量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-19
      • 2022-01-10
      • 1970-01-01
      • 2013-08-30
      • 1970-01-01
      相关资源
      最近更新 更多