时间:12-07-03 栏目:网站开发 作者:admin 评论:0 点击: 7,423 次
<?php /** * * PHP提取SVN信息并上传到FTP * $RCSfile: svn.php $ * $Author: Steven.liao 青剑 * $Revision: 1.0.0 $ * $Date: 2008/03/12 21:50:00 $ */ /*得到精确时间*/ function getmicrotime(){ list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } function get_use_time(){ global $time_start; $time_end = getmicrotime(); $times = $time_end - $time_start; $use_time = "<br />用时:". $times ."秒<br />"; return $use_time; } function replace_path($str){ $str = str_replace('\\/','\\',$str); $str = str_replace('/','\\',$str); return $str; } set_time_limit(0); header("Content-type:text/html; charset=utf-8"); flush(); $time_start = getmicrotime(); //计算时间开始 echo 'start...'; flush(); $ftpserver = 'www.site.com';//ftp server $ftpuser = '';//ftp user name $ftppassword = '';//ftp user password $svnrepository = "d:\\wwwroot\\";//版本库副本所在的路径 $svnbinpath = "D:\\Program Files\\CollabNet\\Subversion Client\\svn.exe";//svn可执行文件路径 $subdir = ''; if($v1 = $_GET['s']) {//版本号 $r = array();//执行外面svn命令返回的信息数组 $f = array();//匹配文件 $fa = array();//所有需上传的匹配文件 if($v2 = $_GET['e']) {//至版本号(从起始版本号至版本号所有文件) exec('"'.$svnbinpath."\" log $svnrepository -r {$v1}:{$v2} -q -v",$r,$return); } else {//单版本号 exec('"'.$svnbinpath."\" log $svnrepository -r {$v1} -q -v",$r,$return); } foreach($r as $value) { if(preg_match("/^[ ]*[AM]{1} (\/.+)$/i",$value,$f)) {//符合文件更新规则的文件名放入上传数组 $fa[] = $f[1]; } } echo "版本: $v1 ".(($v2)?" - $v2":'')."需要上传的文件:\n<br>"; foreach($fa as $value) { echo replace_path($svnrepository.$value)."\n<br>"; } //exit(); if($fa) { $conn_id = ftp_connect($ftpserver); $login_result = ftp_login($conn_id,$ftpuser,$ftppassword); if ((!$conn_id) || (!$login_result)) { echo "FTP connection has failed! :(\n<br>"; exit(); } else { echo "\n<br>Connected to $ftpserver ftp\n<br>"; } echo "\n<br>Current directory: " . ftp_pwd($conn_id) . "\n"; if($subdir){ if (ftp_chdir($conn_id, $subdir)) { echo "Current directory is now: " . ftp_pwd($conn_id) . "\n"; } else { echo "Couldn't change directory\n"; } } foreach($fa as $value) { $remote_path = './'.str_replace('\\','/',$value); $local_path = replace_path($svnrepository.$value); $upload = ftp_put($conn_id,$remote_path, $local_path, FTP_BINARY); if($upload) { // echo "upload $value succeed :)\n<br>"; echo "upload $remote_path <strong>from</strong> $local_path succeed :)\n<br>"; } else { echo "upload $value failed :(\n<br>"; } flush(); } echo "upload completed"; ftp_close($conn_id); } flush(); } else {//无参数提示 ?> 请输入版本号参数s,如需连续多个版本则加上参数e <form action="" method="get"> <p>版本库</p> <p>从: <input name="s" value="" size="5" /> </p> <p>到: <input name="e" value="" size="5" /> (不填也可以) </p> <p> <input name="sub" value="开始上传" type="submit" /> </p> </form> <? } ?>
声明: 本文由( admin )原创编译,转载请保留链接: PHP提取SVN信息并上传到FTP
------====== 本站公告 ======------
联系信息:
电话:19970108113(微信同号) QQ:3142401606
支付宝:https://me.alipay.com/lxq73061
相关插件程序等信息均会在站内发布,敬请关注。