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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 6, 2006 Author Share Posted December 6, 2006 how about specific files? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 7, 2006 Author Share Posted December 7, 2006 THanks :D Quote Link to comment 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 :) Quote Link to comment 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] Quote Link to comment 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 :) Quote Link to comment 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] Quote Link to comment 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 Quote Link to comment 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? :) Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 7, 2006 Author Share Posted December 7, 2006 thanks it worked well! ;) Quote Link to comment 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 Quote Link to comment 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.