function imce_scan_directory in IMCE 5
Same name and namespace in other branches
- 6.2 inc/imce.page.inc \imce_scan_directory()
- 6 inc/page.inc \imce_scan_directory()
- 7 inc/imce.page.inc \imce_scan_directory()
scan directory and return file list and total size of dir.
1 call to imce_scan_directory()
- imce_browse in ./
imce.module - Image Browser.
File
- ./
imce.module, line 400
Code
function imce_scan_directory($dir) {
if (!is_dir($dir) || !is_readable($dir) || !($handle = @opendir($dir))) {
drupal_set_message(t('Error opening directory'), 'error');
return FALSE;
}
$directory = array(
'size' => 0,
'files' => array(),
'folders' => array(),
);
while (($file = readdir($handle)) !== FALSE) {
if ($file == '.' || $file == '..' || $file == 'CVS' || $file == '.svn' || $file == '.htaccess') {
continue;
}
if (is_dir($dir . '/' . $file)) {
$directory['folders'][] = $file;
continue;
}
$path = $dir . '/' . $file;
$size = filesize($path);
$ext = strtolower(substr($file, strrpos($file, '.')));
$img = in_array($ext, $GLOBALS['imce_ext']) ? @getimagesize($path) : array(
0,
0,
);
$date = filemtime($path);
$directory['files'][$path] = array(
'f' => $file,
's' => $size,
'w' => (int) $img[0],
'h' => (int) $img[1],
'd' => $date,
);
$directory['size'] += $size;
}
closedir($handle);
return $directory;
}