我的图片

RSS订阅

  • RSS 2.0
  • 版权声明
人间四月芳非尽,山寺桃花始盛开。常恨春归无觅处,不知转入此山来~!

PHP大型Web应用入门一.02

2006-09-02 11:40:37

天气: 晴朗 心情: 高兴

<?php

// BSM Template Class v1.03喜悦空间-m ? KP#E+}
// By Dr.NP喜悦空间6Z @y5?DWc9D/h%@
// Create data: 11-26-2005

class BsmTpl {

    var $classname                = 'BsmTpl';喜悦空间0K+s6Av_D:` G
    喜悦空间o5A%dxk&p-A
    var $tpl_root_dir            = 'templates/';
b0P { WgGuest    var $tpl_cache_root_dir        = 'sitedata/template/';
!k.qVf1lYQGuest    var $tpl_dir                = '';
P~O'|kh4C%[Guest    喜悦空间"p6L;Ii+B6k;P6SGz
    var $tpl_file_ext            = 'htm';喜悦空间8\pxtQ.j&Sl
    var $tpl_cache_file_ext        = 'php';
*WEtBN9\ o9gGuest    var $tpl_lang_file_ext        = 'lang';
)o*`:OL H*j(`Guest    var $tpl_static_file_ext    = 'html';喜悦空间EZ S%Y d
   
i j0r;j%k2|j$T^Guest    var $tpl_name                = 'default';
)Z d9Gam"RT9`})g FnGuest    var $default_tpl_name        = 'default';喜悦空间(tp_7{_9{0s ~ a%|*~5O
    喜悦空间;] u Z6_~*UkZ
    var $default_db_handle        = '$db';
y,UO%VjX-`Y+YGuest    var $default_lang            = 'zh-cn';喜悦空间X{K,bHh l
   
iX'W`u5GAo2mGuest    function BsmTpl ($root_dir = '', $cache_root_dir = '')喜悦空间#Lfm$N6Ysz
    {喜悦空间qZ2i~w!M
        if ($root_dir != '')
F%P{+t;T b [ yGuest            $this->tpl_root_dir = $root_dir;
tp(oQD"t#IM!eGuest        喜悦空间{-`JReR~:o oi
        if ($cache_root_dir != '')喜悦空间W%D!vPngm^
            $this->tpl_cache_root_dir = $cache_root_dir;
V,C1q9nn'\r,@1W#hGuest    }喜悦空间^i2m)?'b3C1J
   
[_R#f#o/rt3BGuest    function parse_template ($tplfile, $objfile)
8t1q1w J?#Cg vGuest    {
~,A"a'm)\m%J*U)K,Bb$]Guest        $nest = 5;
9QYi U^+kjlGuest       
X$VJhEHJNGuest        if (!@$fp = fopen ($tplfile, 'r')) {喜悦空间(@4Eu_-|+Y N6G5P|g
            die ("Current template file '" . $tplfile. " ' not found or have no access!");喜悦空间Lj.FbT(f7a2HW9|
        }
m$C?(v0ZdJGuest       
(O1Cg\4D)H*PO/RGuest        $template = fread ($fp, filesize ($tplfile));
p6e ^:Vrbu$I!f5`Guest        fclose ($fp);
7aF9Vut {8MGuest        喜悦空间2|:X9~.Ug,mR ^.{}
        $var_regexp = "((\$[a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*)([[a-zA-Z0-9_\"'$x7f-xff]+])*)";
Ploozr7F8EzDK(mZGuest        $const_regexp = "([a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*)";
oW:hZ%jGuest        喜悦空间w4J`}]vr
        $template = preg_replace ("/s*{templates+(.+?)}s*/ies", "file_get_contents('{$this->tpl_dir}\1.{$this->tpl_file_ext}')", $template);
ys*A:d#r1\~rH|9^8QoGuest        喜悦空间mEx!sz2cU {
        $template = preg_replace ("/([nr]+)t+/s", "\1", $template);喜悦空间'`.J jZ@'HV
        $template = preg_replace ("/<!--{(.+?)}-->/s", "{\1}", $template);喜悦空间$R+m8B9? LJ|
        //$template = preg_replace ("/{langs+(.+?)}/ies", "languagevar('\1')", $template);
4x$eB3v SGuest        $template = str_replace  ("{LF}", "<?=\"\n\"?>", $template);喜悦空间MB};B;N&`7m
       
Bv \j LGuest        $template = preg_replace ("/{(\$[a-zA-Z0-9_[]'\"$x7f-xff]+)}/s", "<?=\1?>", $template);喜悦空间Y&Y ^7A5kj
        $template = preg_replace ("/$var_regexp/es", "addquote('<?=\1?>')", $template);喜悦空间7}+J2t^&pqO
        $template = preg_replace ("/<?=<?=$var_regexp?>?>/es", "addquote('<?=\1?>')", $template);喜悦空间okde.F3s/d9Q
       
z?}k0N Yhb6YGuest        $template = preg_replace ("/s*{evals+(.+?)}s*/ies", "stripvtags('n<?php \1 ?>n', '')", $template);
?+Fw7H j{^5?8J-GGuest        $template = preg_replace ("/s*{elseifs+(.+?)}s*/ies", "stripvtags('n<?php } elseif(\1) { ?>n', '')", $template);喜悦空间7ev9l[W
        $template = preg_replace ("/s*{else}s*/is", "n<?php } else { ?>n", $template);
F4?f\;H&D KDGuest        $template = preg_replace ("/s*{dates+(.+?)s+(.+?)}s*/ies", "stripvtags('n<?php echo date (\1, \2 ) ?>n', '')", $template);喜悦空间W8VN `2My#H1@
       
0~8?t O:n_*k?:g Y @BlGuest        for($i = 0; $i < $nest; $i++) {喜悦空间 J%a*{3F%hW;B
            $template = preg_replace ("/s*{loops+(S+)s+(S+)}s*(.+?)s*{/loop}s*/ies", "stripvtags('n<? if(is_array(\1)) { foreach(\1 as \2) { ?>','n\3n<? } } ?>n')", $template);
"Rl*a w#["LGuest            $template = preg_replace ("/s*{loops+(S+)s+(S+)s+(S+)}s*(.+?)s*{/loop}s*/ies", "stripvtags('n<? if(is_array(\1)) { foreach(\1 as \2 => \3) { ?>','n\4n<? } } ?>n')", $template);
{F5U.y'h;W u DVGuest            $template = preg_replace ("/s*{ifs+(.+?)}s*(.+?)s*{/if}s*/ies", "stripvtags('n<? if(\1) { ?>','n\2n<? } ?>n')", $template);喜悦空间1ZI:F:k7Y+|.ug
        }
1Q9\d9j U9w2VGuest       
aw!Nn#vc4AGuest        $template = preg_replace ("/{$const_regexp}/s", "<?=\1?>", $template);
z/K9JB~7h:g vz"BGuest        $template = preg_replace ("/ ?>[nr]*<? /s", " ", $template);喜悦空间3v"KC ]"Tskp}
        喜悦空间5k*c EO \l4Bt3K4F
        /*喜悦空间XkCGq
        $int = preg_match_all ("/->parse('<?=(.+?)?>')/ies", $template, $arr);
^$Eh6AP)_%cA'IGuest       
-_yH:uZ;_N'h,vGuest        for ($i = 0; $i < sizeof ($arr[0]); $i++) {喜悦空间.q*e:w lV,e#M;S
            $template = str_replace ($arr[0][$i], '->parse(' . $arr[1][$i] . ')', $template);喜悦空间nPC7`,}-l
        }
;kR5S]3jYGuest        */
^l~m8F(KJ.keGuest       
`t(qNXO(u)W:}Guest        $template = str_replace ('<!--NOW_TIMESTAMP!-->', '<?php echo time(); ?>', $template);
x mP,b ffF DGuest        $template = str_replace ('<!--NUM_QUERIES!-->', '<?php echo ' . $this->default_db_handle . '->num_queries; ?>', $template);喜悦空间#W4B S"So s$Z$ES
       
?)~ V1DV4K#W*NGuest        /*喜悦空间9w-w!RaU%W.dE
        if (!@$fp = fopen($objfile, 'w')) {喜悦空间&v5W+X i:e
            die ("Directory '" . $this->tpl_root . '/' . $this->tpl_cache_root . "' not found or have no access!");
$p*t0}+\`wbGuest        }喜悦空间o.\;_F-\B]k
        喜悦空间,V^a A0D5n r.D z
        flock ($fp, 3);喜悦空间2jZNHy;K ]
        fwrite ($fp, $template);喜悦空间9J3t3y$o&Hd']
        fclose ($fp);
#I,OI$\ xj7?7K*EGuest        */
"Py/F0GZI.I QCGuest       
Q.|v/e._P8DGuest        return $template;喜悦空间#\)^@J,PTC r-`:w
    }喜悦空间*g nD$G@w
    喜悦空间|/r2oc$^
    function parse ($file)
/Uz1N!G&i7G,|"R zGuest    {
7i4F)w.x`%\V%\Guest        global $page_time, $page_time_start;
g V.|t!w0lp#aGuest       
6XAKKr fGuest        $tplfile = $this->tpl_dir . $file . '.' . $this->tpl_file_ext;
&H| x:^pP\Guest        $objfile = $this->tpl_cache_root_dir . '/' . $this->tpl_name . '_' . $file . '.tpl.' . $this->tpl_cache_file_ext;喜悦空间,o3?}ouAm(k#G
        喜悦空间{(L'L+?z
        if (!file_exists($tplfile)) {
M~iN&OzGuest            $tplfile = $this->tpl_root_dir . '/' . $this->default_tpl_name . '/' . $file.'.'.$this->tpl_file_ext;喜悦空间}%J(e| K6F[
            $objfile = $this->tpl_cache_root_dir . '/' . $this->default_tpl_name . '_' . $file . '.tpl.' . $this->tpl_cache_file_ext;喜悦空间Bh{ mo }0Zw
        }
@j%x2\#[:Q.m3_JGuest        喜悦空间&E/j`FNz"D
        if ((@filemtime($tplfile) > @filemtime($objfile)) || (!@file_exists($objfile))) {喜悦空间m3J|O's-kD
            //$this->parse_template ($tplfile, $objfile);喜悦空间Q-Y5n Wht
            if (!@$fp = fopen($objfile, 'w')) {喜悦空间2m3G l_ Ii$P
                die ("Directory '" . $this->tpl_root . '/' . $this->tpl_cache_root . "' not found or have no access!");喜悦空间9}N%q n?N sU]H#w
            }喜悦空间 zi$p#xI(R
           
9tKW%ivthGuest            flock ($fp, 3);喜悦空间_O@]4{VB)w*F
            fwrite ($fp, $this->parse_template ($tplfile, $objfile));
|Sf$ZxGuest            fclose ($fp);
Sxy]&T p,yeLOGuest        }
dJBiD[2W+FGuest        list ($usec, $sec) = explode (" ", microtime ());
)y V)b[|+i@?1MGuest        $page_time_end = $usec + $sec;喜悦空间wT:L*w5DD8Qy
        $page_time = sprintf ("%0.6f", $page_time_end - $page_time_start);喜悦空间 Z k)s'B)F
        喜悦空间)K/G+s"W'K3k9J7Ls
        return $objfile;喜悦空间3i.sS2|"U H1^C
    }
0B| Y8_2_?%LGuest   
0C Kg}"?VDGuest    function set_tpl_db_handle ($dh)
\#h1_ K1gI%z}.P2BGuest    {
0Xe;jhPpGuest        $this->defalt_db_handle = '$' . $dh;喜悦空间5F2?q6} `
    }
zm_M/a8ysWGuest    喜悦空间:b9py{n[ s-^.d K
    function set_tpl_name ($name)喜悦空间}y+c.g?6qX3N({ _L8_
    {喜悦空间"L1SZ&UW1PH1~'UC
        $tpl_dir = $this->tpl_root_dir . '/' . $name . '/';喜悦空间g5Dty&h_H0JS k
        if ($name != '' && is_dir ($tpl_dir)) {
-pm3y!i.B s0K,\bGuest            $this->tpl_name = $name;喜悦空间-^;L[ Z1a/U
            $this->tpl_dir = str_replace ('//', '/', $tpl_dir);喜悦空间&wG_!U/p!I0ua1hh
        }
A,O3JV8fY m2lGuest        else {喜悦空间wn:u$Q{$^
            $this->tpl_name = $this->default_tpl_name;
9n!u@@`1\Guest            $this->tpl_dir = str_replace ('//', '/', $this->tpl_root_dir . '/' . $this->tpl_name . '/');喜悦空间 KSx];R2lVy
        }喜悦空间\ l'K%x8yj7t
       
[6p&p"y$\W_v:GGuest    }
y,[X4M#Y@9^V L8SGuest   
!b3ZJ8R\GEj QrGuest    function set_language ($langMeta)喜悦空间`T8{ mKWp0VrB K
    {喜悦空间 vn2H'r wN:L
        $langFile = $this->tpl_dir . $langMeta . '.lang';
xg Sa5~,nGuest        clearstatcache ();喜悦空间zJP(UKZi
       
@b6P|m7LL2Nd"fGuest        if (@is_readable ($langFile)) {
\@`P)x4RAGuest            return $langFile;喜悦空间4RN[8pT?#Et?j
        }喜悦空间"g0l,M k3j
       
h/["v-db K?/IGuest        elseif (@is_readable ($this->tpl_dir . $this->default_lang . '.' . $this->tpl_lang_file_ext)) {
;j)r*|G8YRGuest            $langFile = $this->tpl_dir . $this->default_lang . '.' . $this->tpl_lang_file_ext;喜悦空间NL0fp-W}"Vo
            $langMeta = $this->default_lang;
8F;|"i Tt+]6F7CzGuest            return $langFile;喜悦空间*PH[:}g @.t
        }
IYNl X @YGuest       
:^&i^ ];U&aGuest        elseif (@is_readable ($this->tpl_root_dir . '/' . $this->default_tpl_name . '/' . $langMeta . '.lang')) {
DCA8[W{Guest            $langFile = $this->tpl_root_dir . '/' . $this->default_tpl_name . '/' . $langMeta . '.lang';喜悦空间] i)tVu8}7[
            return $langFile;
bHgtXc dgGuest        }喜悦空间:D(V)]A&Y
       
qE,Sc2X9Y5q/okWGuest        elseif (@is_readable ($this->tpl_root_dir . '/' . $this->default_tpl_name . '/' . $this->default_lang . '.' . $this->tpl_lang_file_ext)) {喜悦空间|!EH'U)pwx%\
            $langFile = $this->tpl_root_dir . '/' . $this->default_tpl_name . '/' . $this->default_lang . '.' . $this->tpl_lang_file_ext;喜悦空间8F1}&_*c \z
            $langMeta = $this->default_lang;喜悦空间P$[g$X6@,_b6Q7xq
            return $langFile;喜悦空间 H XG/_mb
        }喜悦空间A3VK B5yYu\ w b:S
       
~4F|a2HaKx?Guest        else
b"_\ d8^;? t+q SGuest            die ('Accept Langfile:' . $langFile . ' did not exist or has no access!');
+h3l|0j1V1Rf9[Guest    }喜悦空间 L L9_}7}_
    喜悦空间z"@ OOgz1?
    function dsp ()
.?u/r8O2uGuest    {喜悦空间9T E z"tB!` x!\@
        global $mSession;喜悦空间$Zs a2C(Up)_v j
        if ($mSession['do_gzip']) {喜悦空间Rj(D?)h#_,K vA
            $gzip_contents = ob_get_contents ();喜悦空间+H*F4xP8V!S.j
            ob_end_clean ();
I6j#Qqs&~!hGuest           
IfGR6Q]c7AGuest            $gzip_size = strlen ($gzip_contents);
&v Ur+Y!] j5v XeWGuest            $gzip_crc = crc32 ($gzip_contents);喜悦空间"_AP kwU
           
0{vP1Cd~{9n&npGuest            $gzip_contents = gzcompress ($gzip_contents, 9);
e7SlS0rn Z V2W:AGuest            $gzip_contents = substr ($gzip_contents, 0, strlen ($gzip_contents) - 4);喜悦空间 OBm i&I UK }4@
            喜悦空间6y3QcbX e3^.Yg
            echo "x1fx8bx08x00x00x00x00x00";
f1P'a aZMGuest            echo $gzip_contents;喜悦空间M(xq'Bk;j&]jt
            echo pack ('V', $gzip_crc);喜悦空间I8pXm"H)f^
            echo pack ('V', $gzip_size);
1w3D#N_M.a vhGuest        }
4|/@T8{N(h1L G,VGuest        else
&_ L9^*b#j2t-R3cUhGuest            ob_end_flush ();
fmywW~8`0jGuest    }喜悦空间*j0Zvy5N(F N
   
H*b1O0j_-S D(iGuest    function get_static_html ($file)
$k.hFT.d6j2`Guest    {
6o+f-W~*N1D)WGuest        // Just for Test...
4eN!iU{j'v1Y5~_Guest        喜悦空间O;^)k k k;Z5B-p6f R
        $static_file = '../../data/static/' . $file . '.' . $this->tpl_static_file_ext;
C0W%Wy$PS q8VGuest        if (@$fp = fopen ($static_file, 'wb')) {
Ke `b!c C@ cDGuest            fwrite ($fp, ob_get_contents ());
F"X vI(KM6ScGuest            fclose ($fp);
fP V5OsUc]Guest        }
'eSP,mZ)STGuest        喜悦空间2M#[%J}+HlZt r
        ob_end_clean ();喜悦空间4n%@!@Ve?:Q@(E
        return;
u9s:xnlJGuest    }
B)yB#BeGuest}

function addquote ($var)喜悦空间.s*px:zB
{
-x:AdeQ*V1yGuest    return str_replace("\\"", """, preg_replace("/[([a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*)]/s", "['\1']", $var));喜悦空间%O6]S%IH/z#I k*S
}
Zc2mxhGuest    喜悦空间@1j4M6q2sW+}3OW
function stripvtags ($expr, $statement)喜悦空间"xd:`,Cc.]?'fN6s;Nw
{喜悦空间U|p(aJi.Z|
    $expr = str_replace("\\"", """, preg_replace("/<?=(\$[a-zA-Z_x7f-xff][a-zA-Z0-9_[]\"'x7f-xff]*)?>/s", "\1", $expr));
n#ut:B-X RGuest    $statement = str_replace("\\"", """, $statement);
Y4e9B9^&u"E+e BGuest    return $expr . $statement;喜悦空间mg)x| ^G
}
"z&{I&p xGuest    喜悦空间5L Is:xR7GF1N
?>
8p6\6qGs-nGuest后面附了一个简单的获取静态页的方法,其实也没什么用,大家都有更好的方法来生成静态页。喜悦空间 YC2TV5\*?]"B'i/o n
    喜悦空间 mMg8d$x/C)i+F/T
    *        *        *        *        *        *
DJd2V:JJeGuest   
F1I dTq~9fbGuest    主要就是这些东西支撑起一个系统运行的必要部分。我从来不强调MVC层次,也不去讲究OOP,虽然偶尔也写一些很蹩脚的类。多年以来Pascal、C和汇编养成的习惯使我相比注意OO结构之外更注意执行效率。这次只是罗列了一些基于共享内存和tmpfs的优化方法。
0oV)_(Z.y {X+}(B}Guest    至于把什么样的数据放在tmpfs上,各位自己看着办。我把include文件、session、模板的编译结果、cache文件放在了上面。 在提升IO性能的同时,它带来的另一个好处是不需要把这些文件放在web目录里,也提高了不少安全性。即使有一些文件需要放在web目录下,比如程序执行文件(废话……),也不要用奇怪的扩展名。对于config.inc.php这样的文件尤其要注意,不要使用config.inc这种文件名,很有可能你的系统忘了配置对.inc的支持,访问者可以直接在浏览器里访问config.inc就可以把这个文件下载走了,而这个文件里保存着你的数据库密码……
~^ `nG/l~@Guest    走到这里,我们已经逐渐地跟上了优化的步伐,在后面的时间里,优化程序结构的同时,已经可以做好更输入地挖掘系统潜力的的准备了。将优化进行到底,挑战一下一台服务器到底能撑住多少个访问者是我近期的变态目标。不过再走下去,可能已经走出了PHP的领地,各位一定要有心理准备,因为我的C程序写得有时候比天书还乱…………hoho
`f5u7I.R0A!sGuest    附上那个压缩/解压的类:

喜悦空间2v,|/F~.oj
<?php喜悦空间E2muB)|#A
class BsmPkg
z Tajd|.q0s&eXI CGuest{
n6Pq,Ho/op,sQGuest    //This class operates with PKG archive format...Haha喜悦空间9T]8Z3Zk3W
    //By Dr.NP 02-15-2006喜悦空间 R [&Dl:y"G&gV\
    喜悦空间#yRw&}3QX f7N!Ng:y^
    var $classname                    = 'BsmPkg';喜悦空间lZ_$lc-g
    var $source_dir                    = '';喜悦空间Q-z:neOuU Q
    var $target_dir                    = '';
\-G3a7r,? k vcGuest    var $filename                    = '';喜悦空间I!ny ]1W i"|E
    var $max_filesize                = 1048576;喜悦空间-AY ~Bf
    喜悦空间e;O e ` R
    var $error_msg                    = '';
k8xyD R[PGuest    var $line_ret                    = "n";喜悦空间,XrT3IeCgN$_
   
m8ztu6a+l `Guest    function pack_from_dir ()喜悦空间J/b)w"Cp'X'Gx
    {
Ds*l-?`FGuest        ini_set ('memory_limit', '32M');喜悦空间4aM!Q PO2B L
        global $content;喜悦空间1|W+xv+MZ*}
        喜悦空间R"Qe AR5u
        $source_dir = $this->source_dir ? $this->source_dir : './';喜悦空间#mI%[^:b!r
        喜悦空间T9S;k-D3lpb?-g,e(B
        $content = '<==PACKAGE_START==>' . $this->line_ret;
9f4M's2B7g&bGuest        $this->_GetDirs ($source_dir);喜悦空间g-b$c Q)Fz
        $content .= '<==PACKAGE_END==>';
S _'NV"z5X ^Guest        $zfp = gzopen ($this->filename, 'wb9');
U,M'T G4di,loGuest        gzwrite ($zfp, $content);
(g _/L%s?k&uGuest        gzclose ($zfp);
Ky%Xj$U,nH8HGuest        return;喜悦空间3o^ Gk6u%o,t7Q
    }喜悦空间 {,b2_hz(C)xj.A
   
:\y1b-oR*Hl [,t/zGuest    function unpack_into_dir ()
:]kZ$\@ aGuest    {喜悦空间!}}@,Ea8s
        ini_set ('memory_limit', '32M');喜悦空间 hz8Q9i5z_|v R
       
$R+H)x }TGuest        $target_dir = $this->target_dir ? $this->target_dir : './';喜悦空间[p] TWx\
        $zfp = gzopen ($this->filename, 'rb');喜悦空间(NdLZV(hy
        $content = gzread ($zfp, $this->max_filesize);
6UvBR8@-T$r hvGuest        gzclose ($zfp);喜悦空间Ucr#J3ETp o
        $lines = explode ($this->line_ret, $content);
,?C-hG9h&ji5YKGuest        while (list ($key, $line) = each ($lines)) {
`-Y6hg!l tN b+mkGuest            if (preg_match ("/<==Directory:([0-7]+)==>(S+)<==/Directory==>/is", $line, $march)) {喜悦空间H"~)u&i*zc|k
                $access_str = $march[1];喜悦空间l!LKD5f4|
                $item_dir = $march[2];喜悦空间X0^+[ IN(P
                if (!is_dir ($target_dir . $item_dir)) {
3Y}p-n~lGuest                    mkdir ($target_dir . $item_dir);喜悦空间*p}@"F"K"] t%z
                    @chmod ($target_dir . $item_dir, intval ($access_str, 8));
6|#qcj O7|+f2BL#@P$WdGuest                }喜悦空间zl&A@a c.@"U
            }
PHa7Tl8LP:yGuest           
/NhzMK"|u7L.cjGuest            if (preg_match ("/<==File:(d+)-([0-9a-f]+)-([0-7]+)==>(S+)<==/File==>/is", $line, $march)) {
)} IM)HLZ(B M7q!\Guest                $target_file = $march[4];
M9Xc1HC0o A0mT:M8PGuest                $access_str = $march[3];
H'H$p wtLGuest                $target_file_checksum = $march[2];
jM1T0o2S;rI m~5GGuest                $target_filesize = $march[1];喜悦空间*n9Hw-d8@5m{,w
                喜悦空间sbWj'\.^HI;M
                if (!@$fp = fopen ($target_dir . $target_file, 'wb')) {
/H']S!I5yYH%[nu*nGuest                    continue;
.rT:u J;P]~4u O4diGuest                }
Hj`&O'S%WMGuest                喜悦空间iC"C8];|`(]
                if (false === (list ($key, $content) = each ($lines))) {   
J9C@|^R0qTGuest                    continue;
jT@.L m:|:LGuest                }
pk+q&^.E%]q5ZGuest                喜悦空间P+RryX
                $file_content = base64_decode (trim ($content));喜悦空间`;|w"{6Ya
                喜悦空间 mj5~V0Vuy|,m
                if (!@fwrite ($fp, $file_content)) {喜悦空间2hS&S"Esd7z)U]
                    continue;
F\"L9|DYXGuest                }喜悦空间r%_hk A.t&X"a
                喜悦空间b.V{h^8hJ,x1j
                fclose ($fp);
g&?UP JGuest                喜悦空间\ Gt`rXK
                if (!@md5_file ($target_file) == $target_file_checksum) {
{+t axOa5w/y(G({)yGuest                    $this->error_msg = 'File : ' . $target_dir . $target_file . 'CheckSum Failed...';喜悦空间:u$Ab].X-Ym veq
                }喜悦空间Eih*FQk%h?
        喜悦空间.t'?E] vTBqZ
                @chmod ($target_dir . $target_file, intval ($access_str, 8));喜悦空间`!xT2eA
           
%[ Q0_Klr]Guest            }
9m:U8{G]v-K3GGuest        }喜悦空间Zd8a r c~mY
        return;
,Qr/XlY1i aGuest    }
${z+x!@9PL KRGuest   
zp#Vl.ZK+m-c"ZGuest    function _GetDirs ($dirname)喜悦空间x$a3L cI&`9V\*f
    {喜悦空间Q+VK ^w}G'r Dn\S
        global $content;
)ih7BWa)N4t sUGuest       
m%XS}t)_2v^Guest        $dh = opendir ($dirname);
zx-C }ne uGuest       
8H*N1o8ut Xg/PGuest        while (false !== ($item = readdir ($dh))) {
{9D V&}-AGuest            $full_itemname = str_replace ('//', '/', $dirname . '/' . $item);
s+L|A&b!_1VGuest            if (strpos ($full_itemname, $this->source_dir) === 0)
J.bKr&vtGuest                $pkg_itemname = substr ($full_itemname, strlen ($this->source_dir));
^&jd:FhBg,m:D4_7WGuest            else喜悦空间h@ M@/a3^Sk5_
                continue;
k-R#b2BC*B%ag:nGuest           
1td6[sb0mGuest            if ($item != '.' && $item != '..' && $item != $this->filename) {
I5n)xn:}I,}*nGuest                if (is_dir ($full_itemname)) {喜悦空间v'v vZl6R yee
                    $access_str = substr (decoct (fileperms ($full_itemname)), -4);喜悦空间G ]&B(j-vT N
                    $content .= "<==Directory:{$access_str}==>$pkg_itemname<==/Directory==>{$this->line_ret}";
T0Sg&r8P#sM/PSIGuest                    $this->_GetDirs ($full_itemname);
jH#|)M'b/^/yGuest                }喜悦空间|s(B'z!R9c
                喜悦空间{R%bQ6HX
                elseif (is_file ($full_itemname) && is_readable ($full_itemname)) {喜悦空间*m^9Q |} X!jKn:Xa
                    $filesize = filesize ($full_itemname);
x^3\C:CD ~UGuest                    $checksum = md5_file ($full_itemname);
4~NMH5V+h z,w[?XGuest                    $access_str = substr (decoct (fileperms ($full_itemname)), -4);喜悦空间2UW7\*CA\
                    $content .= "<==File:{$filesize}-{$checksum}-{$access_str}==>$pkg_itemname<==/File==>{$this->line_ret}";喜悦空间r1f6`k"[8BEbs_.a
                    喜悦空间b)Mgf/K*\.xV
                    @$fp = fopen ($full_itemname, 'rb');喜悦空间x!\*a yA6W+q4g
                    if ($filesize > 0)
7@n(js{+o2cGuest                        $source_file_str = fread ($fp, $filesize);喜悦空间7r*`/i!Yw m
                    else喜悦空间 W~j(|)y [ @
                        $source_file_str = '';
,s(n["r GGuest                    $base64_str = base64_encode ($source_file_str);
Jl1k)w ^ny4MGuest                    fclose ($fp);
M2Ord3mSGuest                   
Iff!C!T6rs Z.z.DGuest                    $content .= $base64_str . $this->line_ret;喜悦空间%P @#~yd:|[!D;J
                }喜悦空间ufP @ePy k
            }
s-JU8A zqbGuest        }喜悦空间7wy#g"^M
        return;喜悦空间m|$o Z3p~j{
    }
6b}&U x!t"QOGuest}喜悦空间eL"s.`#dXa7c
?>


加入收藏 编辑 审核

TAG: PHP

我来说两句

我的日历

« 2009-01-07  
    123
45678910
11121314151617
18192021222324
25262728293031

统计信息

  • 访问数:5576
  • 日志数:63
  • 图片数:5
  • 文件数:0
  • 商品数:0
  • 书签数:0
  • 建立时间:2006-09-01
  • 更新时间:2008-07-07

最新评论

我的收藏

最新好友

最新留言

OPEN

Powered by X-Space 1.1 © 2001-2006 Comsenz Technology Ltd
冀ICP备06023166号