Jump to content

Problem with showing/hiding files with list directory.


ted_chou12

Recommended Posts

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
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
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
[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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.