Jump to content

converting opendir() and similar functions to ftp functions


jakebur01

Recommended Posts

I am having trouble converting the functions in this class into ftp functions.

function getFiles($path) { 

   $files = array(); 
   $fileNames = array(); 
   $i = 0; 
   // build 
   if (is_dir($path)) { 
       if ($dh = opendir($path)) { 
           while (($file = readdir($dh)) !== false) { 
               if (($file == ".") || ($file == "..")) continue; 
               $fullpath = $path . "/" . $file; 
               //$fkey = strtolower($file); 
               $fkey = $file; 
               while (array_key_exists($fkey,$fileNames)) $fkey .= " "; 
               $a = stat($fullpath); 
               $files[$fkey]['size'] = $a['size']; 
               if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-"; 
               else if ($a['size'] > 1024 && $a['size'] <= 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K"; 
               else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb"; 
               else $files[$fkey]['sizetext'] = $a['size'] . " bytes"; 
               $files[$fkey]['name'] = $file; 
               $e = strip_ext($file); // $e is the extension - for example, .gif 
               $files[$fkey]['type'] = filetype($fullpath); // file, dir, etc 
               $k=$e.$file; // we use this string for sorting the array elements by extension and filename; 
               $fileNames[$i++] = $k; 
           } 
           closedir($dh); 
       } else die ("Cannot open directory:  $path"); 
   } else die ("Path is not a directory:  $path"); 
   sort($fileNames,SORT_STRING); // sorting 
   $sortedFiles = array(); 
   $i = 0; 
   foreach($fileNames as $f) { 
           $f = substr($f, 4, strlen($f)-4); // we remove the extension we added in front of the filename for sorting 
           if($files[$f]['name'] !='') $sortedFiles[$i++] = $files[$f];    
    }// ends the foreach where we build the final sorted array 
   return $sortedFiles; 
} 

 

Archived

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

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