Jump to content

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

 

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.