How to set php varible set in php and get filenames fromfolder

how do i get a list of all the filenames of files in C:xampphtdocsdumpuploads in php varible them get the value of php varible in js

Answer

Serverside Read the files.

$files = [];
if ($handle = opendir('.')) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {
            $files[] = $entry;
        }
    }
    closedir($handle);
}

Render the page and echo $files in script tag. like below:

<script type="text/javascript">
    const files = JSON.parse(<?php echo "'".json_encode($files)."'"; ?>);    
    console.log('myFiles', files); 
</script>