Exemplo n.º 1
0
<?php

include 'api_common.inc.php';
//$_GET['fid'] = des_decrypt(base64_decode($_GET['fid']), $TRIPLEDES_KEY, $TRIPLEDES_IV);
//检查传参
if (empty($_GET['fid']) || empty($_GET['ppfeature']) || !isset($_GET['start']) || empty($_GET['end'])) {
    die(json_encode(array('err' => '403', 'msg' => 'fid or ppfeature or start or end empty', 'data' => array())));
}
//得到ppfeature、start,end对应的upload_url
$key = "{$_GET['start']}_{$_GET['end']}";
$ranges = api_cache($_GET['ppfeature'], $key);
if (empty($ranges)) {
    die(json_encode(array('err' => 502, 'msg' => '传参start、end不对', 'data' => [$_GET, $_SERVER['REQUEST_URI'], $_SERVER['argv'], $_SERVER['SERVER_ADDR'], php_uname()])));
}
//处理nginx接收到的文件
$target = UPLOAD_DIR . "/{$_GET['ppfeature']}";
@mkdir($target);
$target .= "/{$key}";
rename($_GET['upload_tmp_path'], $target);
//文件大小校验
if ($_GET['end'] - $_GET['start'] != filesize($target)) {
    die(json_encode(array('err' => 502, 'msg' => '文件不完整', 'data' => [$_GET, $_SERVER['REQUEST_URI'], $_SERVER['argv'], $_SERVER['SERVER_ADDR'], php_uname()])));
}
//传swift
$uploadId = send_put_file($ranges['upload_url'], $target);
if (!$uploadId) {
    die(json_encode(array('err' => 500, 'msg' => '传文件至公有云出错', 'data' => array())));
}
//通知已完成
$md5 = strtoupper($uploadId);
$url = API_CLOUDPLAY . "/2/file/{$_GET['fid']}/action/uploaded?fromcp=private_cloud&range_md5={$md5}&bid={$ranges['bid']}&uploadid={$uploadId}";
Exemplo n.º 2
0
    ajaxReturn('', '公有云接口出错', 500);
}
//获取上传范围
$url = API_CLOUDPLAY . "/2/file/{$_POST['fid']}/action/uploadrange?fromcp=private_cloud&feature_pplive={$_POST['ppfeature']}&segs=1&asyncMD5=true";
if (!$IS_LOCAL) {
    $url .= '&inner=true';
}
$json = send_get($url);
$rangeRs = json_decode($json, 1);
//如果已经上传完成,提交md5和feature
if ($return['data']['fileSize'] == $return['data']['finished']) {
    //cli模式下异步提交最后的md5和feature
    $cacheDir = UPLOAD_DIR . "/cache/{$_POST['ppfeature']}";
    if (is_dir($cacheDir)) {
        $binPath = strpos(PHP_OS, 'WIN') === false ? '/usr/local/php5/bin/php' : 'D:\\wamp\\bin\\php\\php5.5.12\\php.exe';
        $binPath = $IS_LOCAL[0] == 'localhost.idc.pplive.cn' ? '/usr/local/php5.5.27/bin/php' : $binPath;
        $phpPath = __DIR__ . "/api_cli_curl.php {$_POST['fid']} {$_POST['ppfeature']}";
        pclose(popen("{$binPath} {$phpPath} &", 'r'));
    }
    api_cache($_POST['ppfeature'], null);
} else {
    if (empty($rangeRs['data']) || empty($rangeRs['data']['ranges'])) {
        ajaxReturn('', '公有云接口出错', 500);
    }
    $ranges = $rangeRs['data']['ranges'][0];
    $return['data']['ranges'] = array('start' => $ranges['start'], 'end' => $ranges['end'] + 1);
    $key = $ranges['start'] . '_' . ($ranges['end'] + 1);
    api_cache($_POST['ppfeature'], $key, $ranges);
}
$return['data']['nextUrl'] = "{$URL_PREFIX}/uploadRange.php";
ajaxReturn($return['data'], 'success', 0);