i'm trying to make an autocomplete that will display the name of files in a folder. The autocomplete is ok except the part that it only display for the last file name. your help and suggestions much appreciated! =)
code to open the folder and list the excel file names.
if ($handle = opendir('C:AppServ/data')) {
echo "Directory handle: $handle\n";
echo "Entries:\n";
while (false !== ($entry = readdir($handle))) {
$withext = basename("$entry", ".d").PHP_EOL;
$info = pathinfo($withext);
$file_name = basename($withext,'.'.$info['extension']);
$only_year = preg_replace( "/[^0-9]/", "", $file_name );
$only_file = preg_replace( "/[^a-z]/i", "", $file_name );
}
closedir($handle);
}
autocomplete code
<script>
$(function() {
var availableTags = ["<?php echo $only_file; ?>"
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>