Jump to content


Photo

filetype in root = OK, in subfolders = a mess...


  • Please log in to reply
3 replies to this topic

#1 The_Holy_One

The_Holy_One
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 25 May 2006 - 01:48 PM

$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);
   }
}

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.

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 25 May 2006 - 01:54 PM

try using exact paths like /var/www/test
else you could use ../backup make sure 2 .'s as 1 normaly executes a files..


Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 The_Holy_One

The_Holy_One
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 25 May 2006 - 03:03 PM

Still dont work, even with hardlinks like C:\abc\...

#4 The_Holy_One

The_Holy_One
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 25 May 2006 - 04:55 PM

I found a better Solution:
    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 "";  
    }





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users