Basically I need to list the contents of a folder and output it as a list of hyperlinks while excluding anything with an SWF file type. Actually, it'll only be linking specifically to HTML files. I've been using a snippet of code for a while which has worked well in the past, but it looking at it, I can only exclude specific files by name, and not file type. I've hit up Google, but to be honest, I'm not sure what I'm looking at. Code: <ul> <? $path = "./files/"; $narray=array(); $dir_handle = @opendir($path) or die("Unable to open $path"); $i=0; while($file = readdir($dir_handle)) { if(is_dir($file)) { continue; } else if($file != '.' && $file != '..') { //echo "<li><a href='$path/$file'>$file</a></li>"; $narray[$i]=$file; $i++; } } rsort($narray); for($i=0; $i<sizeof($narray); $i++) { echo "<li><a href=".chr(34).$path.$narray[$i].chr(34).">".$narray[$i]."</a></li>"; } //closing the directory closedir($dir_handle); ?> </ul>
http://php.net/manual/en/function.mime-content-type.php http://www.php.net/manual/en/ref.fileinfo.php
You could also explode $file by "." then the last item in the split array should be the extension - you can then match that against the excluded filetypes. eg: Code: $filetype = array_pop(explode(".",$file));
It depends on the definition of "file type". If "file type" equals the extension checking, then yeah, of course your solution is the better one. But if someone wants the real file type, then he must use the magic.mime file .