Robin Robin - 10 months ago 87
PHP Question

PHP scandir not working for relative path

I have a folder called

in my current directory but when I try to run the code below I get the following error:

PHP Warning: scandir(../images,../images): The system cannot find the file specified. (code: 2) in C:\Program Files (x86)\Ampps\www\dev\php\recolor_png\dir.php on line 4

$dir = "../images";

$a = scandir($dir);


I've tried every variation of the path I can think of (
images, /images/, "images", 'images'
etc. but no joy.

var_dump (is_dir('/images'));
also gives

Please help?

Answer Source

Try to use __DIR__ constant

$dir = __DIR__ . "/images";