Robin Robin - 14 days ago 6
PHP Question

PHP scandir not working for relative path

I have a folder called

images
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


<?php
$dir = "../images";

$a = scandir($dir);

print_r($a);


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
false


Please help?

Answer

Try to use __DIR__ constant

$dir = __DIR__ . "/images";
Comments