<?php
require '../connForms/acdet.php';

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

$mysqli = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);

//$userName = $mysqli->real_escape_string($userName);

$sql = "SELECT username='$userName' FROM accounts";
$result = $mysqli->query($sql);

if ($result->num_rows > 0) {

    function allFiles($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('.', '..'));
        $arr = "";
        for ($i = 2; $i < count($files); $i++) {
            if ($i < count($files) - 1) {
                $arr .= $files[$i].",";
            } else {
                $arr .=$files[$i];
            }
        }
        return $arr;
    }
    $response = allFiles($path);
}

$mysqli->close();

echo $response;

?>