0

When I use this code (below) it gives me 3 errors. Is it me or Wampserver? What should I do?

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

print_r($o);
?>

Error 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

Error 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

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

2 回答 2

1

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

$dir = "/gallery/";

$dir = "gallery";
于 2014-02-18T10:35:23.963 回答
0

你需要纠正你的路径。在路径中的任何内容之前使用斜杠将指定C:\wamp目录。哼哼 $dir = "/gallery";,会调查的C:\wamp

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

your_file_being_executed.php
gallery
    img.jpg

你可以使用$dir = "gallery"; And if 结构是

some_dir
   your_file_being_executed.php
gallery
   img.jpg

然后你可以使用$dir = "../gallery";

你也可以__Dir____FILE__语言常量。

于 2014-02-18T10:43:06.213 回答