You are here

function imce_scan_directory in IMCE 6

Same name and namespace in other branches
  1. 5 imce.module \imce_scan_directory()
  2. 6.2 inc/imce.page.inc \imce_scan_directory()
  3. 7 inc/imce.page.inc \imce_scan_directory()

Scan directory and return file list, subdirectories, and total size.

1 string reference to 'imce_scan_directory'
imce_process_profile in inc/page.inc
Get files and folders of the actve directory. Do custom processing.

File

inc/page.inc, line 895

Code

function imce_scan_directory($dirname) {
  $directory = array(
    'dirsize' => 0,
    'files' => array(),
    'subdirectories' => array(),
    'error' => FALSE,
  );
  $dirpath = file_directory_path() . '/' . $dirname;
  if (!is_string($dirname) || $dirname == '' || !($handle = opendir($dirpath))) {
    imce_inaccessible_directory($dirname);
    $directory['error'] = TRUE;
    return $directory;
  }
  $exclude = array(
    '.' => 1,
    '..' => 1,
    'CVS' => 1,
    '.svn' => 1,
    '.htaccess' => 1,
  );
  while (($file = readdir($handle)) !== FALSE) {
    if (isset($exclude[$file])) {
      continue;
    }
    $path = $dirpath . '/' . $file;
    if (is_dir($path)) {
      $directory['subdirectories'][] = $file;
      continue;
    }
    $width = $height = 0;
    if ($img = imce_image_info($path)) {
      $width = $img['width'];
      $height = $img['height'];
    }
    $size = filesize($path);
    $date = filemtime($path);
    $directory['files'][$file] = array(
      'name' => $file,
      'size' => $size,
      'width' => $width,
      'height' => $height,
      'date' => $date,
    );
    $directory['dirsize'] += $size;
  }
  closedir($handle);
  sort($directory['subdirectories']);
  return $directory;
}