il problema è in

if (is_dir("$dirName$file")) {

fallo diventare

if (is_dir("{$dirName}/{$file}")) {