<?php

$userName = $_POST['userName'];
$path = "../shapeDetect/".$userName."/myCustomXML/";

function allFiles() {
    //$path    = "user1/";
    global $path;
    $files = scandir($path);
    //the line below clears . and .. from the first two positions
    //but the array still starts from 2 index that's why we use the for loop
    //$files = array_diff(scandir($path), array('.', '..'));
    $str = "";
    for ($i = 2; $i < count($files); $i++) {
        if ($i < (count($files)-1)) {
            $str .= $files[$i].",";
        } else {
            $str .= $files[$i];
        }
    }
    return $str;
}

$allXMLFiles = allFiles();
 
echo $allXMLFiles;


?>