Hi there,
I need to check for a specific extension (eg: ".txt") inside a directory.
If the files are there they get listed in a table.
If they are not then the user gets a message saying eg: "No such files here".
Here is what I have so far...I can't seem to display the "No such files here" message without repeating several times with the loop.
$fileList = scandir($dir);
rsort($fileList); //to see the latest file on top
function extCheck($fileArray, $filename, $extAllow){
if(substr($fileArray[$filename],-3,3)==$extAllow){
$GLOBALS['list'] = $list;
$list = "<a href=\"".$urlClientString.$fileArray[$filename]."\" >".$fileArray[$filename]."</a>".
" - added on ".
date ("F d Y", filemtime($fileArray[$filename])).
"<br/>";
echo $list;
}
else
{
unset($fileArray[$filename]);//trying to delete all files, except the ones with ".txt" extension
//The array seems to refill itself each time though
}
}
for($fNum=0,$fCount = count($fileList); $fNum<$fCount; $fNum++){
extCheck($fileList, $fNum, "txt");
}
if(!$list){//Checking if $list contains any string...
echo "There are no reports in your database.";
}