$bucket = BucketName;
################################################################################
$object = "path/to/my/Sublime Text 2.0.2.dmg";
$file = "/Users/caoli/Downloads/Sublime Text 2.0.2.dmg";
$fp = fopen($file, 'rb');
SCS::setExceptions(true);
try {
    //初始化上传
    $info = SCS::initiateMultipartUpload($bucket, $object, SCS::ACL_PUBLIC_READ);
    $uploadId = $info['upload_id'];
    $fp = fopen($file, 'rb');
    $i = 1;
    $part_info = array();
    while (!feof($fp)) {
        //上传分片
        $res = SCS::putObject(SCS::inputResourceMultipart($fp, 1024 * 512, $uploadId, $i), $bucket, $object);
        if (isset($res['hash'])) {
            echo 'Part: ' . $i . " OK! \n";
            $part_info[] = array('PartNumber' => $i, 'ETag' => $res['hash']);
        }
        $i++;
    }
    //列分片
    $parts = SCS::listParts($bucket, $object, $uploadId);
    //print_r($parts);
    //print_r($part_info);
    if (count($parts) > 0 && count($parts) == count($part_info)) {
        foreach ($parts as $part_number => $part) {
            //echo $part['etag'] . "\n";
            //echo $part_info[$k]['ETag'] . "\n";
            if ($part['etag'] != $part_info[$part_number - 1]['ETag']) {
Ejemplo n.º 2
0
SCS::setAuth(AccessKey, SecretKey);
$bucket = BUCKETNAME;
$object = PREFIX . basename($uploadFile);
$file = $uploadFile;
$realsize = SCS::realFileSize($file);
$uploadSize = 0;
$fp = fopen($file, 'rb');
//初始化上传
$info = SCS::initiateMultipartUpload($bucket, $object, SCS::ACL_PUBLIC_READ);
$uploadId = $info['upload_id'];
$fp = fopen($file, 'rb');
$i = 1;
$part_info = array();
$piece_size = 1024 * 1024 * 2;
while (!feof($fp)) {
    $udata = SCS::inputResourceMultipart($fp, $piece_size, $uploadId, $i);
    $res = SCS::putObject($udata, $bucket, $object);
    if (isset($res['hash'])) {
        $part_info[] = array('PartNumber' => $i, 'ETag' => $res['hash']);
        $uploadSize += strlen($udata['data']);
        $percent = round($uploadSize / $realsize * 100);
        echo 'Part: ' . $i . " {$uploadSize} / {$realsize} = {$percent}% OK \n";
        $i++;
    } else {
        fseek($fp, -strlen($udata['data']), SEEK_CUR);
    }
}
//列分片
$parts = SCS::listParts($bucket, $object, $uploadId);
if (count($parts) > 0 && count($parts) == count($part_info)) {
    foreach ($parts as $part_number => $part) {