Jump to content

Recommended Posts

[code]
$dir = ".";

if (is_dir($dir)) {
   if ($dh = opendir($dir)) {
       while (($file = readdir($dh)) !== false) {
            $id = filetype($file);
            echo "$id: $datei";
               echo "$file <br />";
       }
       closedir($dh);
   }
}
[/code]

As long my $dir is "." all filetypes will be correctly shown like this:
dir: .
dir: ..
file: 28448513943d2cf0fb5908.gif
dir: backup
file: CIMG0117.JPG

But if i change the directory for example "./backup" or ".\backup" i get a lot of failure messages and i have really NO IDEA Why !, the links seems to work, otherwise it wouldnt print out the list at the bottom after the failure message. What i am doing wrong ? if i comment //$id = filetype($file); i get the whole list, even from subfolders but if i try to get there "type" it mess up.

btw. i want code me a function which print me out DIR with $dir and $flag=0; or FILE's with $dir and $flag=1;

I am happy for everbody who helps me.
Link to comment
https://forums.phpfreaks.com/topic/10435-filetype-in-root-ok-in-subfolders-a-mess/
Share on other sites

I found a better Solution:
[code]
    function filelist($startdir) {  
         //list the directory/file names that you want to ignore  
         global $directorylist;    //initialize global array  
         $ignoredDirectory[] = ".";  
         $ignoredDirectory[] = "..";  
         $ignoredDirectory[] = "_vti_cnf";  
         if (is_dir($startdir)) {  
              if ($dh = opendir($startdir)) {  
             while (($file = readdir($dh)) !== false) {  
                   if (!(array_search($file,$ignoredDirectory) > -1)) {  
                 $directorylist[$startdir . $file]['name'] = $file;  
              $directorylist[$startdir . $file]['path'] = $startdir;  
              $directorylist[$startdir . $file]['typ'] = filetype($startdir . $file);  
                        }  
                   }  
              }  
        closedir($dh);  
         }  
         return($directorylist);  
    }
    
    $files = filelist($_SESSION['current_dir']."/"); // call the function  
    if ($files != ""){  
         foreach ($files as $list) {//print array  
              if ($list['typ'] == "dir"){  
                   $dirname = $list['name'];  
                   echo "<a href='?dir=$dirname'>".$list['name']."</a><br />";  
              }  
         }  
    } else {  
         echo "";  
    }
[/code]
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.