bfc36d1be9d60243329507311af12714ce530fe0.svn-base 1.7 KB

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