mcmuney Posted February 6, 2010 Share Posted February 6, 2010 I'm using the code below to display all files within a folder and sub-folder; however, I'd like to modify to show only 2 types of file. Can anyone help with the mod? <?php $filelist = explode("\n",`find .|sort`); // for each item (file) in the array... for ($count=0;$count<count($filelist);$count++) { // get the filename (including preceding directory, ie: ./software/gth1.0.9.tar.gz) $filename=$filelist[$count]; // if it's not a directory, display linked if (!is_dir($filename)) printf("<font face='Verdana' size='2'><b><a href=\"%s\">%s</a></b></font><br>\n",$filename,$filename); } ?> Link to comment https://forums.phpfreaks.com/topic/191117-display-only-certain-file-extensions/ Share on other sites More sharing options...
trq Posted February 6, 2010 Share Posted February 6, 2010 $filelist = glob("{*.jpg,*.gif}", GLOB_BRACE); Link to comment https://forums.phpfreaks.com/topic/191117-display-only-certain-file-extensions/#findComment-1007737 Share on other sites More sharing options...
mcmuney Posted February 6, 2010 Author Share Posted February 6, 2010 That works, but only for the main folder, but doesn't show anything for the sub-folder. Link to comment https://forums.phpfreaks.com/topic/191117-display-only-certain-file-extensions/#findComment-1007740 Share on other sites More sharing options...
trq Posted February 6, 2010 Share Posted February 6, 2010 Then you will need to either write a recursive function to go through directories, or, if your not worried about platform independence, go back to your original method. $filelist = explode("\n",`find . -name '.jpg' -name '.gif' |sort`); Link to comment https://forums.phpfreaks.com/topic/191117-display-only-certain-file-extensions/#findComment-1007748 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.