You are here

function imce_scan_directory in IMCE 7

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. 6 inc/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/imce.page.inc
Get files and folders of the actve directory. Do custom processing.

File

inc/imce.page.inc, line 1117
Implements the file browser.

Code

function imce_scan_directory($dirname, $imce) {
  $directory = array(
    'dirsize' => 0,
    'files' => array(),
    'subdirectories' => array(),
    'error' => FALSE,
  );
  $diruri = imce_dir_uri($imce, $dirname);
  if (!is_string($dirname) || $dirname == '' || !($handle = opendir($diruri))) {
    imce_inaccessible_directory($dirname, $imce);
    $directory['error'] = TRUE;
    return $directory;
  }
  while (($file = readdir($handle)) !== FALSE) {

    // Do not include dot files or folders, or the UNIX lost+found directory.
    if (substr($file, 0, 1) === '.' || $file == 'lost+found') {
      continue;
    }
    $path = $diruri . $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;
}