• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

Scandir Alternative Help me

My host won't allow php5 so i can't use scandir function could anyone help with a alternative to scandir() ?
I've tried what php manual said  and failed for hours! Thank you :(    

      function _check_dir($file) {
            $dir = opendir($file);
            $pliki = array();
            $numer = 0;
            $dupa = scandir($file);
            foreach ($dupa as $file2) {
                  if ((filetype($file.'/'.$file2)=='file')&&($file2!='.')&&($file2!='..')) {
                        $numer++;
                        $pliki[$numer] = $file2;
                  }
            }
            return $pliki;
      }
      
      $tablica = array();
      //zwracamy po prostu liste katalogow.
      $nrkat = 0;
      $katalog = scandir('.');
      foreach ($katalog as $file) {
            if ((filetype($file)=='dir')&&($file!='.')&&($file!='..')) {
                  $nrkat++;
                  $tablica[$nrkat]['name'] = $file;
                  $tablica[$nrkat]['files'] = _check_dir($file);
            }
      }
      echo serialize($tablica);
0
jags2ooo
Asked:
jags2ooo
1 Solution
 
BinkersCommented:
PHP4 uses the functions opendir to open a directory and readdir to read the next file in the directory.  To use those in your code you could do this.

function _check_dir($file) {
            $dir = opendir($file);
            $pliki = array();
            $numer = 0;
            $dupa = opendir($file);
            while (false !== ($file2 = readdir($dupa))) {
                    if ((filetype($file.'/'.$file2)=='file')&&($file2!='.')&&($file2!='..')) {
                              $numer++;
                              $pliki[$numer] = $file2;
                    }
            }
            return $pliki;
  }
     
  $tablica = array();
  //zwracamy po prostu liste katalogow.
  $nrkat = 0;
  $katalog = opendir('.');
  while (false !== ($file = readdir($katalog))) {
            if ((filetype($file)=='dir')&&($file!='.')&&($file!='..')) {
                    $nrkat++;
                    $tablica[$nrkat]['name'] = $file;
                    $tablica[$nrkat]['files'] = _check_dir($file);
            }
  }
  echo serialize($tablica)
0
 
jags2oooAuthor Commented:
Perfect Thank you Binkers!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now