Jump to content

Archived

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

The_Holy_One

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

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.

Share this post


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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.