Extjs中加载带中文的目录..

使用ext-4.0.7-gpl\examples\tree 文件夹下面的文件

1.reorder.html

2.reorder.js

3.get-nodes.php

更改方法, 将get-nodes.php内容替换成如下

<?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.’ );
}
$node = iconv ( ‘utf-8’, ‘gb2312’, $node );
$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 ();

function __jsonText($array) {
    $str = "{";
    foreach ( $array as $key => $value ) {
        $value = str_replace ( "\"", "\\\"", $value );
        if ($str != "{")
            $str .= ",";
        $str .= "$key: " . "\"$value\"";
    }
    $str .= "}";
   
    return $str;
}
$strNode = "";

foreach ( $nodes as $key => $value ) {
    $strNode .= __jsonText ( $value ) . ",";
}
$strNode = sprintf ( ‘[%s]’, iconv ( ‘gb2312’, ‘utf-8’, rtrim ( $strNode, ‘,’ ) ) );
echo $strNode;
/*
* $json = new Services_JSON(); echo $json->encode($nodes);
*/
?>

最后的显示中文的结果图

002