Example #1
0
 $n_files = count($files);
 //php sorting
 $sorted = array();
 $current_folder = array();
 $prev_folder = array();
 $current_files_number = 0;
 $current_folders_number = 0;
 foreach ($files as $k => $file) {
     if ($file == ".") {
         $current_folder = array('file' => $file);
     } elseif ($file == "..") {
         $prev_folder = array('file' => $file);
     } elseif (is_dir($current_path . $rfm_subfolder . $subdir . $file)) {
         $date = filemtime($current_path . $rfm_subfolder . $subdir . $file);
         if ($show_folder_size) {
             list($size, $nfiles, $nfolders) = folder_info($current_path . $rfm_subfolder . $subdir . $file);
             $current_folders_number++;
         } else {
             $size = 0;
         }
         $file_ext = trans('Type_dir');
         $sorted[$k] = array('file' => $file, 'file_lcase' => strtolower($file), 'date' => $date, 'size' => $size, 'nfiles' => $nfiles, 'nfolders' => $nfolders, 'extension' => $file_ext, 'extension_lcase' => strtolower($file_ext));
     } else {
         $current_files_number++;
         $file_path = $current_path . $rfm_subfolder . $subdir . $file;
         $date = filemtime($file_path);
         $size = filesize($file_path);
         $file_ext = substr(strrchr($file, '.'), 1);
         $sorted[$k] = array('file' => $file, 'file_lcase' => strtolower($file), 'date' => $date, 'size' => $size, 'extension' => $file_ext, 'extension_lcase' => strtolower($file_ext));
     }
 }
Example #2
0
 if ($action != 'copy' && $action != 'cut') {
     response(trans('wrong action') . AddErrorLocation())->send();
     exit;
 }
 // check for writability
 if (is_really_writable($path) === FALSE || is_really_writable($path_thumb) === FALSE) {
     response(trans('Dir_No_Write') . '<br/>' . str_replace('../', '', $path) . '<br/>' . str_replace('../', '', $path_thumb) . AddErrorLocation())->send();
     exit;
 }
 // check if server disables copy or rename
 if (is_function_callable($action == 'copy' ? 'copy' : 'rename') === FALSE) {
     response(sprintf(trans('Function_Disabled'), $action == 'copy' ? trans('Copy') : trans('Cut')) . AddErrorLocation())->send();
     exit;
 }
 if ($action == 'copy') {
     list($sizeFolderToCopy, $fileNum, $foldersCount) = folder_info($path, false);
     if (!checkresultingsize($sizeFolderToCopy)) {
         response(sprintf(trans('max_size_reached'), $MaxSizeTotal) . AddErrorLocation())->send();
         exit;
     }
     rcopy($data['path'], $path);
     rcopy($data['path_thumb'], $path_thumb);
 } elseif ($action == 'cut') {
     rrename($data['path'], $path);
     rrename($data['path_thumb'], $path_thumb);
     // cleanup
     if (is_dir($data['path']) === TRUE) {
         rrename_after_cleaner($data['path']);
         rrename_after_cleaner($data['path_thumb']);
     }
 }
Example #3
0
/**
* check if the current folder size plus the added size is over the overall size limite
*
* @param  int  $sizeAdded
*
* @return  bool
*/
function checkresultingsize($sizeAdded)
{
    global $MaxSizeTotal, $current_path;
    if ($MaxSizeTotal !== false && is_int($MaxSizeTotal)) {
        list($sizeCurrentFolder, $fileCurrentNum, $foldersCurrentCount) = folder_info($current_path, false);
        // overall size over limit
        if ($MaxSizeTotal * 1024 * 1024 < $sizeCurrentFolder + $sizeAdded) {
            return false;
        }
    }
    return true;
}
Example #4
0
/** 
 * 获取文件夹下列表信息
 * dir 包含结尾/   d:/wwwroot/test/
 * 传入需要读取的文件夹路径,为程序编码
 */
function path_list($dir, $list_file = true, $check_children = false)
{
    $dir = rtrim($dir, '/') . '/';
    if (!is_dir($dir) || !($dh = opendir($dir))) {
        return array('folderlist' => array(), 'filelist' => array());
    }
    $folderlist = array();
    $filelist = array();
    //文件夹与文件
    while (($file = readdir($dh)) !== false) {
        if ($file != "." && $file != ".." && $file != ".svn") {
            $fullpath = $dir . $file;
            if (is_dir($fullpath)) {
                $info = folder_info($fullpath);
                if ($check_children) {
                    $info['isParent'] = path_haschildren($fullpath, $list_file);
                }
                $folderlist[] = $info;
            } else {
                if ($list_file) {
                    //是否列出文件
                    $info = file_info($fullpath);
                    if ($check_children) {
                        $info['isParent'] = false;
                    }
                    $filelist[] = $info;
                }
            }
        }
    }
    closedir($dh);
    return array('folderlist' => $folderlist, 'filelist' => $filelist);
}
Example #5
0
/**
 * Determine directory size
 *
 * @param  string  $path
 *
 * @return  int
 */
function folder_info($path)
{
    $total_size = 0;
    $files = scandir($path);
    $cleanPath = rtrim($path, '/') . '/';
    $files_count = 0;
    $folders_count = 0;
    foreach ($files as $t) {
        if ($t != "." && $t != "..") {
            $currentFile = $cleanPath . $t;
            if (is_dir($currentFile)) {
                list($size, $tmp, $tmp1) = folder_info($currentFile);
                $total_size += $size;
                $folders_count++;
            } else {
                $size = filesize($currentFile);
                $total_size += $size;
                $files_count++;
            }
        }
    }
    return array($total_size, $files_count, $folders_count);
}