1024) {$size/=1024; $suffix=$suxAry[$cnt];} return $suffix?sprintf("%.1f",$size).$suffix:$size.'B'; } function countchar($str,$chr) { return (strlen($str) - strlen(str_replace($chr,'',$str))) / strlen($chr); } function mysort($a, $b) { // row(md5,size,path) $a,$b global $excludes_order,$includes_order,$normal_depth; // basic sort first if($a['size'] != $b['size']) return $a['size'] > $b['size'] ? -1 : 1; if($a['md5'] != $b['md5']) return strnatcmp($a['md5'], $b['md5']); // $a_pathdepth = countchar($a['path'],'/'); // $b_pathdepth = countchar($b['path'],'/'); // deeper path first if(($a['depth'] + $b['depth']) > $normal_depth*2) { if($a['depth'] == $b['depth']) return strnatcmp($a['path'], $b['path']); return $a['depth'] > $b['depth'] ? -1 : 1; } // exclude foreach($excludes_order as $excl) { $a_exclude = !!strstr($a['path'],$excl); $b_exclude = !!strstr($b['path'],$excl); if($a_exclude + $b_exclude) { if($a_exclude == $b_exclude) return strnatcmp(basename($a['path']), basename($b['path'])); else return $a_exclude ? 1 : -1; } } // include foreach($includes_order as $incl) { $a_include = preg_match('|'.$incl.'|i',$a['path']); $b_include = preg_match('|'.$incl.'|i',$b['path']); if($a_include + $b_include) { if($a_include == $b_include) return strnatcmp(basename($a['path']), basename($b['path'])); else return $a_include ? -1 : 1; } } // last: strnatcmp return strnatcmp($a['path'], $b['path']); } function read_and_sort($file, &$ary,$names_only=false) { $ary = array('files'=>array(),'names'=>array()); $f = file(basename($file)); foreach($f as $line) { $file = array(); list($file['md5'],$file['size'],$file['path']) = explode("\t",rtrim($line)); if(!$names_only) { $file['depth'] = countchar($file['path'],'/'); $ary['files'][] = $file; } $ary['names'][$file['path']] = array('md5'=>$file['md5'],'size'=>$file['size']); } if(!$names_only) usort($ary['files'],'mysort'); } function hdr() { // header('Content-Type: text/html; charset=big5'); echo '
'; print_r($_POST['files']); echo '