ted_chou12 Posted December 6, 2006 Share Posted December 6, 2006 See the code below:<?php$dir = ".";$file = readdir($dh);if($dh = opendir($dir)) {while (($file = readdir($dh)) !== false){echo "<table border=0><td><font size=5 face=\"arial\"><b>Username:</b> <a href=\"$file\">$file</a><br></font></td>"."\n";}closedir($dh);}?></table>This is a list directory php script, i want to know if it is possible to both show and hide files.ps. please teach me how to show and hide both specific files (ie. with specific filename), and general types,(eg. types of files with same file extension).THANKS, to anyone who replies with a solution. :D Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/ Share on other sites More sharing options...
joquius Posted December 6, 2006 Share Posted December 6, 2006 Use glob (*.ext) or loop excluding files with extensions you want to hide. Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136170 Share on other sites More sharing options...
ted_chou12 Posted December 6, 2006 Author Share Posted December 6, 2006 how about specific files? Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136177 Share on other sites More sharing options...
joquius Posted December 6, 2006 Share Posted December 6, 2006 [code]$exclude = Array ('file1.ext', 'file2.ext');foreach (glob ($dir."*") as $file) {if (!in_array ($file, $exclude)) echo $file;}[/code]for example Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136181 Share on other sites More sharing options...
ted_chou12 Posted December 6, 2006 Author Share Posted December 6, 2006 thanks :D! i will request for help if i dont understand. Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136182 Share on other sites More sharing options...
ted_chou12 Posted December 6, 2006 Author Share Posted December 6, 2006 opps ??? can you teach me:how do i insert the code into the list directory script please Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136183 Share on other sites More sharing options...
craygo Posted December 6, 2006 Share Posted December 6, 2006 I change it a little, you should be able to copy and paste this[code]<?php$namearray = array("thisfile", "thatfile"); // File names you want to exclude$extarray = array("ini", "txt"); //extension you want to exclude$files = array();if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if($file != "." && $file != ".."){ if(filetype($file) == "file"){ $filearray = explode(".", $file); $files[$filearray[0]] = $filearray[1]; } } }closedir($handle);}foreach($files as $name => $ext){ if(in_array($name, $namearray, false) || in_array($ext, $extarray, false)){ } else { echo "<table border=0><td><font size=5 face=\"arial\">Username: <a href=\"".$name.".".$ext."\">".$name.".".$ext."</font></td>"."\n"; }}?>[/code]Ray Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136241 Share on other sites More sharing options...
ted_chou12 Posted December 7, 2006 Author Share Posted December 7, 2006 THanks :D Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136957 Share on other sites More sharing options...
ted_chou12 Posted December 7, 2006 Author Share Posted December 7, 2006 what about if i want to show directories, is there a way to do that?thanks again :) Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136961 Share on other sites More sharing options...
trq Posted December 7, 2006 Share Posted December 7, 2006 [code=php:0]if (filetype($file) == "file" || filetype($file) == "dir")[/code] Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136964 Share on other sites More sharing options...
ted_chou12 Posted December 7, 2006 Author Share Posted December 7, 2006 where do i add it to? (into the script):if (filetype($file) == "file" || filetype($file) == "dir")thanks for helping :) Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136968 Share on other sites More sharing options...
trq Posted December 7, 2006 Share Posted December 7, 2006 Instead of...[code=php:0]if (filetype($file) == "file")[/code] Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136970 Share on other sites More sharing options...
craygo Posted December 7, 2006 Share Posted December 7, 2006 Ok lets try and get everything here. Are you trying to make a web page to browse through files and directories on your server?? Because I can see the next question being "how to I go to the directory in the list" Please try and tell us everything you want from the start so we don't have to go back to the script 20 times.Ray Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136971 Share on other sites More sharing options...
ted_chou12 Posted December 7, 2006 Author Share Posted December 7, 2006 okay, actually, i just want to know how to hide and show files for listing the directory, however, there were folders included in the directory i wanted to list so i asked. ps. you got the point? :) Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136976 Share on other sites More sharing options...
ted_chou12 Posted December 7, 2006 Author Share Posted December 7, 2006 thanks and appreciated for your help anyways :D Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136977 Share on other sites More sharing options...
craygo Posted December 7, 2006 Share Posted December 7, 2006 [code]<?php$namearray = array("ankycooper", "adduserform", "carttest");$extarray = array("ini", "txt");$files = array();$dir = array();if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if($file != "." && $file != ".."){ if(filetype($file) == "file"){ $filearray = explode(".", $file); $files[$filearray[0]] = $filearray[1]; } if(filetype($file) == "dir"){ $dir[] = $file; } } }closedir($handle);}echo "<table border=0>";echo "<tr> <td align=center><b>Directories</b></td> </tr>";foreach($dir as $dname){ echo "<tr> <td>$dname</td> </tr>";}echo "<tr> <td align=center><b>Files</b></td> </tr>";foreach($files as $name => $ext){ if(in_array($name, $namearray, false) || in_array($ext, $extarray, false)){ } else { echo "<tr>\n <td><font size=5 face=\"arial\">Username: <a href=\"".$name.".".$ext."\">".$name.".".$ext."</font></td>"."\n </tr>\n"; }}?>[/code]Ray Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136980 Share on other sites More sharing options...
ted_chou12 Posted December 7, 2006 Author Share Posted December 7, 2006 thanks it worked well! ;) Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136984 Share on other sites More sharing options...
ted_chou12 Posted December 7, 2006 Author Share Posted December 7, 2006 wow, the one you just pasted is awesome! Ted Link to comment https://forums.phpfreaks.com/topic/29669-problem-with-showinghiding-files-with-list-directory/#findComment-136988 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.