dev-master
9999999-dev https://github.com/CloudSide/SinaCloudStorage-SDK-PHPPHP SDK for 新浪云存储
MIT
The Requires
- php >=5.2.0
by Bruce Chen
sina scs sinastorage
PHP SDK for 新浪云存储
PHP SDK for 新浪云存储, (*1)
composer.phar
进行安装, composer require cloudmario/scs:dev-master 详细信息:https://packagist.org/packages/cloudmario/scsOO method (e,g; $scs->getObject(...)):, (*2)
$scs = new SCS($scsAccessKey, $scsSecretKey);
Statically (e,g; SCS::getObject(...)):, (*3)
SCS::setAuth($scsAccessKey, $scsSecretKey);
Use exceptions, (*4)
SCS::setExceptions(true); try { $response = SCS::getObjectInfo($bucket, $uri); print_r($response); } catch(SCSException $e) { echo $e->getMessage(); }
Put an object from a file:, (*5)
SCS::putObject(SCS::inputFile($file, false), $bucketName, $uploadName, SCS::ACL_PUBLIC_READ);
Put an object from a string and set its Content-Type:, (*6)
SCS::putObject($string, $bucketName, $uploadName, SCS::ACL_PUBLIC_READ, array(), array('Content-Type' => 'text/plain'));
Put an object from a resource (buffer/file size is required - note: the resource will be fclose()'d automatically):, (*7)
SCS::putObject(SCS::inputResource(fopen($file, 'rb'), filesize($file)), $bucketName, $uploadName, SCS::ACL_PUBLIC_READ);
Also use:, (*8)
SCS::putObjectFile($file, $bucket, $uri); SCS::putObjectString($string, $bucket, $uri);
Get an object:, (*9)
SCS::getObject($bucketName, $uploadName);
Get an object info (meta):, (*10)
SCS::getObjectInfo($bucket, $uri, $returnInfo = true);
You can also:, (*11)
SCS::getMeta($bucket, $uri);
Save an object to file:, (*12)
SCS::getObject($bucketName, $uploadName, $saveName);
Save an object to a resource of any type:, (*13)
SCS::getObject($bucketName, $uploadName, fopen('savefile.txt', 'wb'));
Copy an object:, (*14)
SCS::copyObject($srcBucket, $srcName, $bucketName, $saveName, $metaHeaders = array(), $requestHeaders = array());
Delete an object:, (*15)
SCS::deleteObject($bucketName, $uploadName);
Get a list of buckets:, (*16)
SCS::listBuckets(); // Simple bucket list SCS::listBuckets(true); // Detailed bucket list
Create a bucket:, (*17)
SCS::putBucket($bucketName);
Get the contents of a bucket (list objects):, (*18)
SCS::getBucket($bucketName);
Delete an empty bucket:, (*19)
SCS::deleteBucket($bucketName);
Get bucket meta:, (*20)
SCS::getMeta($bucketName);
Get ACL, (*21)
SCS::getAccessControlPolicy($bucket); //for bucket SCS::getAccessControlPolicy($bucket, $uri); //for object
Set ACL, (*22)
$acp = array( 'GRPS000000ANONYMOUSE' => array('read'), 'GRPS0000000CANONICAL' => array('read', 'write'), 'SINA0000001001HBK300' => array('read', 'write', 'read_acp', 'write_acp') ); SCS::setAccessControlPolicy($bucket, $uri, $acp); //for object SCS::setAccessControlPolicy($bucket, '', $acp); //for bucket
mkdir("scs://{$bucketName}"); file_put_contents("scs://{$bucketName}/test.txt", "http://weibo.com/smcz !"); file_get_contents("scs://{$bucketName}/test.txt") foreach (new DirectoryIterator("scs://{$bucketName}") as $b) { echo "\t" . $b . "\n"; } unlink("scs://{$bucketName}/test.txt"); rmdir("scs://{$bucketName}");
$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']) { exit('分片不匹配'); break; } } //合并分片 echo "开始合并\n"; SCS::completeMultipartUpload($bucket, $object, $uploadId, $part_info); echo "上传完成\n"; fclose($fp); } } catch(SCSException $e) { echo $e->getMessage(); }
PHP SDK for 新浪云存储
MIT
sina scs sinastorage