jerome69 Posted October 26, 2009 Share Posted October 26, 2009 Hi everyone i have a php script that list content of a directory. But i want to hide a folder inside this list, i try some many things with no result, someone could help me Here's the code: <select name="folder" id="folder"> <?php // Here we explore UploadedFiles folder and fill "select" element with names of existing folders $d = dir_list(dirname($_SERVER['SCRIPT_FILENAME'])."/../galerie/"); if($d) { foreach($d as $f) { echo "<option value=\"$f\" >$f</option>"; } } ?> </select> Thank you! Jerome Quote Link to comment https://forums.phpfreaks.com/topic/179097-solved-list-dir-how-to-hide-a-folder/ Share on other sites More sharing options...
Alex Posted October 26, 2009 Share Posted October 26, 2009 You should define an array containing directories that you don't want to show. Then within your foreach check to see if the current element is in that array, if it is skip that iteration using the continue keyword. ex $hide = Array('dir1', 'dir2'); ... foreach($d as $f) { if(in_array($f, $hide)) continue; echo "<option value=\"$f\" >$f</option>"; } ... Quote Link to comment https://forums.phpfreaks.com/topic/179097-solved-list-dir-how-to-hide-a-folder/#findComment-944925 Share on other sites More sharing options...
gizmola Posted October 26, 2009 Share Posted October 26, 2009 Just do a string comparison foreach($d as $f) { if ($f !== 'filename to hide') echo "$f"; } Quote Link to comment https://forums.phpfreaks.com/topic/179097-solved-list-dir-how-to-hide-a-folder/#findComment-944931 Share on other sites More sharing options...
jerome69 Posted October 26, 2009 Author Share Posted October 26, 2009 thanks to all of you the code of AlexWD works fine so I use it Jerome Quote Link to comment https://forums.phpfreaks.com/topic/179097-solved-list-dir-how-to-hide-a-folder/#findComment-944965 Share on other sites More sharing options...
gizmola Posted October 26, 2009 Share Posted October 26, 2009 Great -- please mark this as solved. Quote Link to comment https://forums.phpfreaks.com/topic/179097-solved-list-dir-how-to-hide-a-folder/#findComment-944970 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.