Can someone explain why, in this situation, scandir is getting my directory, but the glob is getting...well, it seems like it's getting the path:
$directory = "../../../XXXXXXXXXXXXXX/media/csv";
With scandir:
$files = scandir($directory);
print_r($files);
Result:
Array ( [0] => . [1] => .. [2] => myCsv.csv [3] => index.html )
With Glob:
$files = glob($directory . "*"); # i wanted to select only CSV, but it returned empty. so i placed a *.
Result:
Array ( [0] => ../../../XXXXXXXXXXXXXX/media/csv )
Since your $directory
is something like ../XXX/media/csv
, you need to append it with /*.csv
so it would become ../XXX/media/csv/*.csv
(currently it is ../XXX/media/csv*
).
$files = glob($directory . "/*.csv");