Robin Robin - 1 year ago 117
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";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download