skulky Posted November 30, 2008 Share Posted November 30, 2008 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."; } Link to comment https://forums.phpfreaks.com/topic/134862-checking-directory-for-specific-file-extension/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.