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
Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

[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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.