Skip to content

Commit

Permalink
合并自dev-superfile
Browse files Browse the repository at this point in the history
  • Loading branch information
oott123 committed Oct 15, 2013
2 parents b85fab3 + 1818f51 commit 70085c9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
18 changes: 14 additions & 4 deletions _bpcs_files_/common.inc.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<?php
function echon($str){
echo $str."\n";
function echon($str,$debug=false){
if($debug){
echo $str."\n";
}else{
echo chr(27)."[0;34m".$str.chr(27)."[m\n";
}
}
function getline(){
return trim(fgets(STDIN));
}
function getpath($path){
return '/apps/'.urlencode(trim(file_get_contents(CONFIG_DIR.'/appname')).'/'.$path);
}
function oaerr($arr,$exitonerror = 1){
if(isset($arr['error'])){
echon('OAuth error '.$arr['error'].' : '.$arr['error_description']);
Expand Down Expand Up @@ -38,7 +45,7 @@ function continueornot(){
}
function cmd($cfe) {
$res = '';
echon($cfe);
echon($cfe,1);
$cfe = $cfe;
if ($cfe) {
if(function_exists('exec')) {
Expand All @@ -64,6 +71,7 @@ function cmd($cfe) {
@pclose($f);
}
}
echon($res,1);
return $res;
}
function do_api($url,$param,$method = 'POST'){
Expand All @@ -78,7 +86,9 @@ function do_api($url,$param,$method = 'POST'){
function error_handle($errno, $errstr, $errfile, $errline){
switch ($errno) {
case E_USER_ERROR:
echon("Fatal ERROR : $errfile ($errline) $errstr");die('Exiting with a fatal error.'."\n");
echon("Fatal ERROR : $errfile ($errline) $errstr");
echon('Exiting with a fatal error.'."\n");
die(9002);
break;
case E_USER_WARNING:
echon("WARNING : $errfile ($errline) $errstr");
Expand Down
25 changes: 22 additions & 3 deletions bpcs_uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
echo <<<EOF
===========================Baidu PCS Uploader===========================
usage : $argv[0] init|quickinit|quota
usage : $argv[0] upload|download [path_local] [path_remote]
usage : $argv[0] delete [path_remote]
usage : $argv[0] fetch [path_remote] [path_to_fetch]
usage : $argv[0] upload|download path_local path_remote
usage : $argv[0] delete path_remote
usage : $argv[0] uploadbig path_local path_remote [slice_size(def:1073741824)] [temp_dir(def:/tmp/)]
usage : $argv[0] fetch path_remote path_to_fetch
========================================================================
EOF;
Expand Down Expand Up @@ -94,4 +95,22 @@
}
fetch_file($access_token,$argv[2],$argv[3]);
break;
case 'uploadbig':
//uploadbig - 大文件上传
switch(count($argv)){
case 0:
case 1:
case 2:
case 3: //参数数目不够
echon('Parameters unmatched.');
die(9099);
case 4: //设置默认值(单个文件大小->1G)
$argv[4] = 1073741824;
//因为需要继续下面的操作所以这里没有break
case 5: //设置默认值(临时文件目录->/tmp/)
$argv[5] = '/tmp/';
//因为需要继续下面的操作所以这里没有break
default: //开始上传操作
super_file($access_token,$argv[3],$argv[2],'newcopy',$argv[4],$argv[5]);
}
}

0 comments on commit 70085c9

Please sign in to comment.