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\wwwandom1\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\wwwandom1\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\wwwandom1\index.php on line 3
You are searching for the /gallery/ directory. The first / means it'll start searching from the root. Removing that will make it relative. So change
$dir = "/gallery/";
to
$dir = "gallery";
You need to correct your path. Using a slash before anything in path will specify C:\wamp
directory. Hench $dir = "/gallery";
, it will look into C:\wamp
.
Suppose your directory structure is (in www\your_project directory)
your_file_being_executed.php
gallery
img.jpg
You can use $dir = "gallery";
And if structure is
some_dir
your_file_being_executed.php
gallery
img.jpg
Then you can use $dir = "../gallery";
You can also __Dir__
and __FILE__
language constants.