2 // from php manual page
\r
3 function formatBytes($val, $digits = 3, $mode = "SI", $bB = "B"){ //$mode == "SI"|"IEC", $bB == "b"|"B"
\r
4 $si = array("", "K", "M", "G", "T", "P", "E", "Z", "Y");
\r
5 $iec = array("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi");
\r
6 switch(strtoupper($mode)) {
\r
7 case "SI" : $factor = 1000; $symbols = $si; break;
\r
8 case "IEC" : $factor = 1024; $symbols = $iec; break;
\r
9 default : $factor = 1000; $symbols = $si; break;
\r
12 case "b" : $val *= 8; break;
\r
13 default : $bB = "B"; break;
\r
15 for($i=0;$i<count($symbols)-1 && $val>=$factor;$i++)
\r
17 $p = strpos($val, ".");
\r
18 if($p !== false && $p > $digits) $val = round($val);
\r
19 elseif($p !== false) $val = round($val, $digits-$p);
\r
20 return round($val, $digits) . " " . $symbols[$i] . $bB;
\r
23 $dir = isset($_REQUEST['lib'])&&$_REQUEST['lib'] == 'yui' ? '../../../' : '../../';
\r
24 $node = isset($_REQUEST['node'])?$_REQUEST['node']:"";
\r
25 if(strpos($node, '..') !== false){
\r
26 die('Nice try buddy.');
\r
29 $d = dir($dir.$node);
\r
30 while($f = $d->read()){
\r
31 if($f == '.' || $f == '..' || substr($f, 0, 1) == '.')continue;
\r
32 $lastmod = date('M j, Y, g:i a',filemtime($dir.$node.'/'.$f));
\r
33 if(is_dir($dir.$node.'/'.$f)){
\r
34 $qtip = 'Type: Folder<br />Last Modified: '.$lastmod;
\r
35 $nodes[] = array('text'=>$f, 'id'=>$node.'/'.$f/*, 'qtip'=>$qtip*/, 'cls'=>'folder');
\r
37 $size = formatBytes(filesize($dir.$node.'/'.$f), 2);
\r
38 $qtip = 'Type: JavaScript File<br />Last Modified: '.$lastmod.'<br />Size: '.$size;
\r
39 $nodes[] = array('text'=>$f, 'id'=>$node.'/'.$f, 'leaf'=>true/*, 'qtip'=>$qtip, 'qtipTitle'=>$f */, 'cls'=>'file');
\r
43 echo json_encode($nodes);
\r