喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 喜悦证交所 | 帮助

RSS 订阅当前论坛  

[北京]代朋友公司招聘PHP高级程序员多名

上一主题 下一主题
 12  2/2  <  1  2 
     
标题: 闲时写得一个 Ftp 状态程序  
 
fwolf (fwolf)
金牌会员
Rank: 6Rank: 6
资深会员


UID 19073
精华 0
积分 1227
帖子 1236
金钱 1227 喜悦币
威望 0
人脉 0
阅读权限 70
注册 2003-3-20
来自 河北/石家庄
状态 离线
偶已经搞定,需要拷贝一个字体到程序目录并改名为c.ttf
还要建一个空白JPG文件back.jpg
程序修改几个小地方,贴在下面了
为了看着方便,我把缓存去掉了

<?
/*
* ::
* base definement
* ::
*/

// remote ftp server (use FTP for short below) ip
//define("cHost", "10.1.206.86");
define("cHost""131.2.101.10");
// FTP port, required!
//define("cPort", 21);
define("cPort"8000);
// FTP monitor persisting time, required!
define("cBanMnt"30);
// FTP allowd connect times
define("cBanTms"10);

// cache filename
define("cCacheFile""ftpstats.png");
// source image filename
define("cSrcFile""back.jpg");
// blank pixels number between each 2 lines
define("cLineSpc"5);

// notice:
// until the current moment, all definements were trusted from the program
// in this way, if one or more difinements were given with error values
// program would destroyed.
// so, in the future versions, we need to improve this section.

/*
* **
* function to write a text in a line with different colors, fonts and sizes
*
* syntax:
*     imageWriteLine(<GD_stream_object>, <offset_x>, <offset_y>,
*         <text_desribe_array> [, <text_desribe_array> [, ...]]);
*
* information:
*     GD_stream_object : the GD stream which the text would be drawn
*     offset_x : text block left border offset from the left border of the
*         stream image when the text be thought as a color block or a layer
*     offset_y : text block top border offset from the top border of the
*         stream image when the text be thought as a color block or a layer
*     text_describe_array : a array include text infomation, should be listed
*         as font, size, color, content, shadowd, shadowcolor in order
*
* tip:
*     you can put many text_describe_array in the parameters zone, but there
*         should be 1 at least.
*     with a pleasure in visual, all text_array would be displayed base the
*         same pixel line.
*     to be the return values, the status would be the first item in the array,
*         and if its done, the text block width and height would be the second
*         and the third items.
* **
*/

function imageWriteLine() {
        
$func_args func_get_args();
        
$temp count($func_args);
        
//verify the parameters
        //quiz : how to check the first parameter whether is a gd stream image object?
        
if ($temp || !is_int($func_args[1]) || !is_int($func_args[2])) {
                print(
'error_1');
                unset(
$func_args$temp);
                return(array(
FALSE));
        }
        for (
$i 3$i $temp$i++) {
                if(!
is_array($func_args[$i]) || (count($func_args[$i]) != && count($func_args[$i]) != 6) || !is_string($func_args[$i][0]) || !file_exists($func_args[$i][0]) || !is_int($func_args[$i][1]) || $func_args[$i][1] < || !is_string($func_args[$i][3]) || (count($func_args[$i])== && !is_bool($func_args[$i][4]))) {
                print(
"error_2_$i");
                        unset(
$func_args$temp$i);
                        return(array(
FALSE));
                }
        }
        
$img array_shift($func_args);
        
$off_x array_shift($func_args);
        
$off_y array_shift($func_args);
        
$temp -= 3;
        for (
$i 0$i $temp$i++) {
                
// save font serials in fonts
                
$fonts[] = $func_args[$i][0];
                
// save size serials in sizes
                
$sizes[] = $func_args[$i][1];
                
// save color serials in colors
                
$colors[] = $func_args[$i][2];
                
// save content serials in contents
                
$contents[] = $func_args[$i][3];
                
// save shadowd serials in shadowd
                
$shadowds[] = $func_args[$i][4] ? TRUE FALSE;
                
// save color2 serials in color2s
                
$color2s[] = $func_args[$i][4] ? $func_args[$i][5] : '';
                
// save width serials in width and height serials in heights
                
list($x1$y2$x2, , , $y1, , ) = imageTTFbBox($func_args[$i][1], 0$func_args[$i][0], $func_args[$i][3]);
                
$widths[] = $x2 $x1;
                
$heights[] = $y2 $y1;
        }
        unset(
$func_args$x1$x2$y1$y2);
        
// get true y offset
        
$rslt = array(TRUEarray_sum($widths), max($heights));
        unset(
$heights);
        
$off_y += $rslt[2];
        
// draw text
        
for ($i 0$i $temp$i++) {
                
// if need shadowed, draw shadow
                
if ($shadowds[$i]) imageTTFText($img$sizes[$i], 0, ($off_x 1), ($off_y 1), $color2s[$i], $fonts[$i], $contents[$i]);
                
imageTTFText($img$sizes[$i], 0$off_x$off_y$colors[$i], $fonts[$i], $contents[$i]);
                
$off_x += $widths[$i];
        }
        
// return reports
        
unset($img$off_x$off_y$temp$i$fonts$sizes$colors$contents$widths);
        return(
$rslt);
}

/*
* **
* function to convert a string based on ?????? to unicode
*
* copyrights
*     wroten by 6spring @ BiT.UNioN
*     free for personal usage
*     all rights reserved.
* **
*/

function ??????2uni($text) {

        
// return blank if parameter missed

        
if (!$slen strlen($text)) return("");

        
$rslt $tmp "";

        for (
$i 0$i $slen$i++) {

                
$casc ord($text[$i]);

                if (
$casc >= 160 && $i $slen 1) {

                        
// tip : does your apache tell you that undefined function iconv() ?

                        // coz, you need to load the php_iconv.dll module in php.ini

                        // sounds terribly, you have to copy the iconv.dll from Dlls directory

                        // to system directory such as c:winndowssystem32 too

                        
$tmp bin2hex(iconv("??????""UTF-8"substr($text$i2)));

                        
$rslt .= chr(base_convert(substr($tmp02), 1610));

                        
$rslt .= chr(base_convert(substr($tmp22), 1610));

                        
$rslt .= chr(base_convert(substr($tmp42), 1610));

                        
$i++;

                } else 
$rslt .= $text[$i];

        }

        unset(
$slen$tmp$i$casc$text);

        return(
$rslt);

}



/*

* ::

* task serials

* ::

*/

// if no cache exist, create it

if (file_exists(cCacheFile))
{
    
unlink(cCacheFile);
    
createCache();
}else
{
    
createCache();
}

// push the cached image to client

pushImage();

// if cache expired, update it

//if (ceil(cBanMnt / (cBanTms - 1)) + fileMTime(cCacheFile) + 1 < time()) {

        // delete old expired cache

//        unlink(cCacheFile);

        // create new cache

//        createCache();

//}



/*

* ::

* function to push cached image to client

*

* personal usage in this file

* ::

*/

function pushImage() {

        
// use location direction for fewer treatments

//        header("Location: ".cCacheFile);
echo('<img src="' cCacheFile '"></img>');

/*

        // use a gd image sream for resist truly cache file from end user

        $img = imageCreateFromPNG(cCacheFile);

        imagePNG($img);

        imageDestroy($img);

*/

}
/*

* ::

* function to create a cache image file

*

* personal usage in this file

* ::

*/

function createCache() {

        
// create a gd image stream for source image file

        
list($img_w$img_h, , ) = getImageSize(cSrcFile);

        
$img imageCreateFromJPEG(cSrcFile);

        
// quiz : when source image file couldnt be recognized, what shall we do?

        // report error? or just stop the program?

        // add a black border for graphic stream

        
imageRectangle($img00, --$img_w, --$img_himageColorAllocate($img000));

        
// simple socket connection for ftp info

        
$fsc = @fSockOpen(cHostcPort$ftp_e_no$ftp_e_str1);

        if (
$ftp_e_no) {

                
// treat with the case which FTP is down

                
$ftp_stats = ??????2uni('服务器 维 护 检 修 中');

                list(
$text_x1$text_y2$text_x2, , , $text_y1, , ) = imageTTFbBox(160'c.ttf'$ftp_stats);

                
$text_x2 intval(465 - ($text_x2 $text_x1) / 2);

                
$text_y2 intval(145 + ($text_y2 $text_y1) / 2);

                
imageTTFText($img160, ($text_x2 1), ($text_y2 1), imageColorAllocate($img000), 'c.ttf'$ftp_stats);

                
imageTTFText($img160$text_x2$text_y2imageColorAllocate($img25500), 'c.ttf'$ftp_stats);

        } else {

                
// ftp works ^^

                // collect ftp info

                
socket_set_timeOut($fsc1);

                
$ftp_info "";

                do {

                        
$ftp_info .= fRead($fsc4096);

                } while (!
strpos($ftp_info'Enjoy~~'));

                
fClose($fsc);

                
// treat with the FTP info

                
$ftp_info preg_replace('/n/'''$ftp_info);

                
// FTP downloaded info

                
list($ftp_d_data$ftp_d_file) = split(','preg_replace('/.+220- (d+) KB data in (d+) files been downloaded.+/''$1,$2'$ftp_info));

                
// FTP uploaded info

                
list($ftp_u_data$ftp_u_file) = split(','preg_replace('/.+220- (d+) KB data in (d+) files been uploaded.+/''$1,$2'$ftp_info));

                
// FTP speed info

                
list($ftp_s_avr$ftp_s_cur) = split(','preg_replace('/.+220- (d+.d)d{2} KBps speed averaged, current is (d+.d)d{2} KBps.+/''$1,$2'$ftp_info));

                
// FTP connects info

                
list($ftp_c_usr$ftp_c_log$ftp_c_day) = split(','preg_replace('/.+220- (d+) usrs connectd, (d+) logind, and (d+) last 24 hours.+/''$1,$2,$3'$ftp_info));

                
// FTP current users info

                
list($ftp_n_usr$ftp_a_usr) = split(','preg_replace('/.+220- (d+) named and (d+) anonymous usrs connectd right ?????+/''$1,$2'$ftp_info));

                unset(
$ftp_info);

                
// ready for serialize info output

                
$text_x0 345;

                
$text_x_ 585;

                
$text_y0 105;

                
$text_y_ 185;

                
$color_static imageColorAllocate($img51102153);

                
$color_static_ imageColorAllocate($img01734);

                
$color_var imageColorAllocate($img51153102);

                
$color_var_ imageColorAllocate($img03417);

                
// get FTP status and flush out

                
if ($ftp_s_cur <= 500$ftp_stats '活 力 四 射';

                elseif (
$ftp_s_cur <= 1000$ftp_stats '努 力 工 作';

                elseif (
$ftp_s_cur <= 1500$ftp_stats '疲 劳 不 堪';

                elseif (
$ftp_s_cur <= 2000$ftp_stats '苟 延 残 喘';

                else 
$ftp_stats '生 命 垂 危';

                
$ftp_stats = ??????2uni('━┥ '.$ftp_stats.' ┝━');

                
$font 'c.ttf';

                list(
$text_x1$text_y2$text_x2, , , $text_y1, , ) = imageTTFbBox(130$font$ftp_stats);

                
$text_x intval(($text_x0 $text_x_) / - ($text_x2 $text_x1) / 2);

                
$text_y $text_y0 $text_y2 $text_y1;

                
imageTTFText($img130, ($text_x 1), ($text_y 1), imageColorAllocate($img000), $font$ftp_stats);

                
imageTTFText($img130$text_x$text_yimageColorAllocate($img153153153), $font$ftp_stats);

                
$text_y0 $text_y cLineSpc 2;

//                $fontb = 'e_b.ttf';
//
//                $fonti = 'ei_.ttf';
//
//                $font = 'e__.ttf';
                
$fontb 'c.ttf';

                
$fonti 'c.ttf';

                
$font 'c.ttf';

                
// flush out connects

                
list(, , $text_y) = imageWriteLine($img$text_x0$text_y0,

                        array(
$fontb10$color_static'Connects : 'TRUE$color_static_),

                        array(
$font8$color_var$ftp_n_usrTRUE$color_var_),

                        array(
$fonti10$color_static' of 'TRUE$color_static_),

                        array(
$font8$color_var$ftp_c_usrTRUE$color_var_),

                        array(
$fonti10$color_static' usrs'TRUE$color_static_));

                
$text_y0 += $text_y cLineSpc;

                
// flush out speed

                
list(, , $text_y) = imageWriteLine($img$text_x0$text_y0,

                        array(
$fontb10$color_static'Speed : 'TRUE$color_static_),

                        array(
$font8$color_var$ftp_s_curTRUE$color_var_),

                        array(
$fonti10$color_static' KBps ( 'TRUE$color_static_),

                        array(
$font8$color_var$ftp_s_avrTRUE$color_var_),

                        array(
$fonti10$color_static' avr.)'TRUE$color_static_));

                
$text_y0 += $text_y cLineSpc 3;

                
// flush out downloaded

                
list(, , $text_y) = imageWriteLine($img$text_x0$text_y0,

                        array(
$fontb10$color_static'Downloaded : 'TRUE$color_static_),

                        array(
$font8$color_varpreg_replace('/^(d+.d)d*$/''$1'strval(max(0.1$ftp_d_data 1000000))), TRUE$color_var_),

                        array(
$fonti10$color_static' GB in 'TRUE$color_static_),

                        array(
$font8$color_var$ftp_d_fileTRUE$color_var_),

                        array(
$fonti10$color_static' files'TRUE$color_static_));

                
// free the mem that variables used

                
unset($ftp_d_data$ftp_d_file$ftp_u_data$ftp_u_file$ftp_s_avr$ftp_s_cur$ftp_c_usr$ftp_c_log$ftp_c_day$ftp_n_usr$ftp_a_usr);

                unset(
$text_x0$text_x_$text_y0$text_y_$text_x$text_y$color_static$color_static_$color_var$color_var_$font$fonti$fontb);

        }

        
// free the mem that variables used

        
unset($ftp_stats$text_x1$text_x2$text_y1$text_y2);

        
// write stream to file named cache image filename

        
imagePNG($imgcCacheFile);

        
imageDestroy($img);

}

?>
2004-5-15 12:17 PM#11
查看资料  发短消息  QQ  顶部
 
fwolf (fwolf)
金牌会员
Rank: 6Rank: 6
资深会员


UID 19073
精华 0
积分 1227
帖子 1236
金钱 1227 喜悦币
威望 0
人脉 0
阅读权限 70
注册 2003-3-20
来自 河北/石家庄
状态 离线
[推荐阅读] 查询时的问题
下来再细细研究
2004-5-15 12:18 PM#12
查看资料  发短消息  QQ  顶部
 12  2/2  <  1  2 
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.082687 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP