Search code examples
phppermissionsdirectoryscandir

PHP's scandir() returns false, can't locate directory


I have a directory structure like this:

htdocs--->: dir.php, img(rwxrw-rw-) ---> img1.jpg, img2.jpg

but when I try to use var_dump(scandir('/img'));or var_dump(scandir('/img/')); in dir.php

it simply returns bool(false) and an error message saying it can't find /img/.

Why is this happening?


Solution

  • Unlikely /img directory exists since the leading / means it's at the root level of the hard drive. Try ./img The ./ means THIS directory, eg, the directory the currently running PHP script is in.