tigertim Posted September 29, 2010 Share Posted September 29, 2010 Hi Sorry if this is the wrong place for this but I'm totally stumped here and I know its a basic question but I'm very new to php and I need help :-) Basically all i would like to do is hide certain file types, folders (specifically the folder .AppleDouble) and hidden files, below is my code so far and I'd really appreciate it if anyone could help me out by taking a look! Any help would be very gratefully received! Here's my code so far: <? $rootdir = "../media/Documents"; function printdir($dir) { $dircount = 0; $filecount = 0; $handle = opendir($dir); while (false != ($file = readdir($handle))) { if (@filetype($dir . "/" . $file) == "dir" AND $file != "." AND $file != "..") { $dirlist[$dircount] = $file; $dircount++; } else { if (strtolower(substr($file, -4)) == ".avi") { $filelist[$filecount] = substr($file, 0, (strlen($file)-4)); $filecount++; } } } closedir($handle); if ($dircount>0) {sort ($dirlist);} if ($filecount>0) {sort ($filelist);} for ($i = 0; $i < $dircount; $i++) { echo "<dl>\n"; echo "<dt><B>" . $dirlist[$i] . "</B></dt>\n"; flush(); printdir($dir . "/" . $dirlist[$i]); echo "</dl>\n\n"; } for ($i = 0; $i < $filecount; $i++) { echo "<dd>" . $filelist[$i] . "</dd>\n"; flush(); } if ($filecount + $dircount == 0) { echo "<dd><i><empty folder></i></dd>\n"; } } printdir($rootdir); ?> Link to comment https://forums.phpfreaks.com/topic/214711-how-to-hide-appledouble-folder/ Share on other sites More sharing options...
the182guy Posted September 29, 2010 Share Posted September 29, 2010 For the certain file types part, instead of having if (strtolower(substr($file, -4)) == ".avi") Have something like $allowed = array('.avi', '.jpg', '.gif'); // allowed file types if (in_array(strtolower(substr($file, -4)), $allowed)) // the file extension must be in $allowed to be added As for excluding certain folders, instead of if (@filetype($dir . "/" . $file) == "dir" AND $file != "." AND $file != "..") Have something like $badFolders = array('.AppDouble', 'badfolder2'); // excluded folders if (@filetype($dir . "/" . $file) == "dir" AND $file != "." AND $file != ".." AND in_array($file, $badFolders) == false) Link to comment https://forums.phpfreaks.com/topic/214711-how-to-hide-appledouble-folder/#findComment-1117097 Share on other sites More sharing options...
tigertim Posted October 1, 2010 Author Share Posted October 1, 2010 Perfect! That's exactly what i was trying to do, thanks very much for you help! Link to comment https://forums.phpfreaks.com/topic/214711-how-to-hide-appledouble-folder/#findComment-1118010 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.