这段代码谁能给个.net版的
<?php
// from php manual page
function formatBytes($val, $digits = 3, $mode = "SI", $bB = "B"){ //$mode == "SI"|"IEC", $bB == "b"|"B"
$si = array("", "K", "M", "G", "T", "P", "E", "Z", "Y");
$iec = array("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi");
switch(strtoupper($mode)) {
case "SI" : $factor = 1000; $symbols = $si; break;
case "IEC" : $factor = 1024; $symbols = $iec; break;
default : $factor = 1000; $symbols = $si; break;
}
switch($bB) {
case "b" : $val *= 8; break;
default : $bB = "B"; break;
}
for($i=0;$i<count($symbols)-1 && $val>=$factor;$i++)
$val /= $factor;
$p = strpos($val, ".");
if($p !== false && $p > $digits) $val = round($val);
elseif($p !== false) $val = round($val, $digits-$p);
return round($val, $digits) . " " . $symbols[$i] . $bB;
}$dir = isset($_REQUEST['lib'])&&$_REQUEST['lib'] == 'yui' ? '../../../' : '../../';
$node = isset($_REQUEST['node'])?$_REQUEST['node']:"";
if(strpos($node, '..') !== false){
die('Nice try buddy.');
}
$nodes = array();
$d = dir($dir.$node);
while($f = $d->read()){
if($f == '.' || $f == '..' || substr($f, 0, 1) == '.')continue;
$lastmod = date('M j, Y, g:i a',filemtime($dir.$node.'/'.$f));
if(is_dir($dir.$node.'/'.$f)){
$qtip = 'Type: Folder<br />Last Modified: '.$lastmod;
$nodes[] = array('text'=>$f, 'id'=>$node.'/'.$f/*, 'qtip'=>$qtip*/, 'cls'=>'folder');
}else{
$size = formatBytes(filesize($dir.$node.'/'.$f), 2);
$qtip = 'Type: JavaScript File<br />Last Modified: '.$lastmod.'<br />Size: '.$size;
$nodes[] = array('text'=>$f, 'id'=>$node.'/'.$f, 'leaf'=>true/*, 'qtip'=>$qtip, 'qtipTitle'=>$f */, 'cls'=>'file');
}
}
$d->close();
echo json_encode($nodes);
?>
一直想写个树
觉得ExtJs的树不错,可是是PHP的,看不太懂
谁能给个.net版的链接如下
http://extjs.org.cn/index.php?q=node/153
<?php
// from php manual page
function formatBytes($val, $digits = 3, $mode = "SI", $bB = "B"){ //$mode == "SI"|"IEC", $bB == "b"|"B"
$si = array("", "K", "M", "G", "T", "P", "E", "Z", "Y");
$iec = array("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi");
switch(strtoupper($mode)) {
case "SI" : $factor = 1000; $symbols = $si; break;
case "IEC" : $factor = 1024; $symbols = $iec; break;
default : $factor = 1000; $symbols = $si; break;
}
switch($bB) {
case "b" : $val *= 8; break;
default : $bB = "B"; break;
}
for($i=0;$i<count($symbols)-1 && $val>=$factor;$i++)
$val /= $factor;
$p = strpos($val, ".");
if($p !== false && $p > $digits) $val = round($val);
elseif($p !== false) $val = round($val, $digits-$p);
return round($val, $digits) . " " . $symbols[$i] . $bB;
}$dir = isset($_REQUEST['lib'])&&$_REQUEST['lib'] == 'yui' ? '../../../' : '../../';
$node = isset($_REQUEST['node'])?$_REQUEST['node']:"";
if(strpos($node, '..') !== false){
die('Nice try buddy.');
}
$nodes = array();
$d = dir($dir.$node);
while($f = $d->read()){
if($f == '.' || $f == '..' || substr($f, 0, 1) == '.')continue;
$lastmod = date('M j, Y, g:i a',filemtime($dir.$node.'/'.$f));
if(is_dir($dir.$node.'/'.$f)){
$qtip = 'Type: Folder<br />Last Modified: '.$lastmod;
$nodes[] = array('text'=>$f, 'id'=>$node.'/'.$f/*, 'qtip'=>$qtip*/, 'cls'=>'folder');
}else{
$size = formatBytes(filesize($dir.$node.'/'.$f), 2);
$qtip = 'Type: JavaScript File<br />Last Modified: '.$lastmod.'<br />Size: '.$size;
$nodes[] = array('text'=>$f, 'id'=>$node.'/'.$f, 'leaf'=>true/*, 'qtip'=>$qtip, 'qtipTitle'=>$f */, 'cls'=>'file');
}
}
$d->close();
echo json_encode($nodes);
?>
一直想写个树
觉得ExtJs的树不错,可是是PHP的,看不太懂
谁能给个.net版的链接如下
http://extjs.org.cn/index.php?q=node/153
解决方案 »
- PHP has encountered an Access Violation at 027BAD16
- ecshop
- php 改logo
- 2003+IIS+php5.2要怎么安装和设置php_imagick.dll的支持,整了几天了没成功,PHPINFO里都看不到那
- php 扩展 返回数组的问题
- 开源SNS软件iwebSNS v0.7发布
- 我想拷贝一个php网站,请大侠给我出出主意
- 求 PHP 函数库源码
- 用过PHP的Discuz!论坛,UCenter Home 和 SupeSite的朋友请进
- include一个php文件,经常会失败,请问需要注意些什么?
- 求PHP高手合作
- 请问关于header无法跳转的问题。
-------------------------------------------------------------------<%@ WebHandler Language="C#" Class="get_nodes" Debug="true" %>
#region License
//
// Extjs example aspx version.
// Written by Jamblues ([email protected])
// Copyright (c) 2008 extjs.org.cn. All rights reserved.
//
#endregionusing System;
using System.Web;
using System.Data;
using System.IO;public class get_nodes : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.Charset = "utf-8";
context.Response.ContentType = "text/html";
//context.Response.Write(FormatBytes(10119,2,"SI", "B"));
string lib = context.Request.Params["lib"];
string dir = (lib != null) && (lib == "yui") ? "../../../" : "Script/ext-2.0.2/";
string node = context.Request.Params["node"];
node = (node != null) ? node : "";
if (node.IndexOf("..") > 0)
{
context.Response.Write("Nice try buddy.");
return;
} string path = context.Server.MapPath(".") + "/" + dir + node + "/";
string json = "[";
if (Directory.Exists(path))
{
string[] dirctoryEntries = Directory.GetDirectories(path);
foreach (string directoryName in dirctoryEntries)
{
string myDirectoryName = directoryName.Replace(path, "");
json += "{\"text\":\"" + myDirectoryName + "\",\"id\":\"" + node + "\\/" + myDirectoryName + "\",\"cls\":\"folder\"},";
} string[] fileEntries = Directory.GetFiles(path);
foreach (string fileName in fileEntries)
{
string myFileName = fileName.Replace(path, "");
json += "{\"text\":\"" + myFileName + "\",\"id\":\"" + node + "\\/" + myFileName + "\",\"leaf\":true,\"cls\":\"file\"},";
}
}
else
{
context.Response.Write(path + " is not a valid file or directory.");
}
json += "]";
json = json.Replace(",]", "]");
context.Response.Write(json);
} public bool IsReusable
{
get
{
return false;
}
} public string FormatBytes(double val, int digits, string mode, string bB)
{ //$mode == "SI"|"IEC", $bB == "b"|"B"
string[] si = { "", "K", "M", "G", "T", "P", "E", "Z", "Y" };
string[] iec = { "", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" };
int factor;
string[] symbols;
switch (mode.ToUpper())
{
case "SI": factor = 1000; symbols = si; break;
case "IEC": factor = 1024; symbols = iec; break;
default: factor = 1000; symbols = si; break;
}
switch (bB)
{
case "b": val *= 8; break;
default: bB = "B"; break;
}
int i = 0;
for (; i < symbols.Length - 1 && val >= factor; i++)
val /= factor;
int p = val.ToString().IndexOf(".");
if (p > 0 && p > digits)
val = Math.Round(val);
else if (p > 0)
val = Math.Round(val, digits - p); return Math.Round(val, digits) + " " + symbols[i] + bB; }
}