if (AccessKey == 'change-this' || SecretKey == 'change-this') {
    exit("\nERROR: access information required\n\nPlease edit the following lines in this file:\n\n" . "define('AccessKey', 'change-me');\ndefine('SecretKey', 'change-me');\n\n");
}
// Instantiate the class
$scs = new SCS(AccessKey, SecretKey);
echo "SCS::getAuthenticatedURL(): " . SCS::getAuthenticatedURL('sdk', 'snapshot/snapshot.png', 86400000) . "\n";
// List your buckets:
echo "SCS::listBuckets(): " . print_r($scs->listBuckets(), 1) . "\n";
// Create a bucket with public read access
if ($scs->putBucket($bucketName, SCS::ACL_PUBLIC_READ)) {
    echo "Created bucket {$bucketName}" . PHP_EOL;
    // Put our file (also with public read access)
    if ($scs->putObjectFile($uploadFile, $bucketName, baseName($uploadFile), SCS::ACL_PUBLIC_READ)) {
        echo "SCS::putObjectFile(): File copied to {$bucketName}/" . baseName($uploadFile) . PHP_EOL;
        // Get the contents of our bucket
        $contents = $scs->getBucket($bucketName);
        echo "SCS::getBucket(): Files in bucket {$bucketName}: " . print_r($contents, 1);
        // Get object info
        $info = $scs->getObjectInfo($bucketName, baseName($uploadFile));
        echo "SCS::getObjectInfo(): Info for {$bucketName}/" . baseName($uploadFile) . ': ' . print_r($info, 1);
        // You can also fetch the object into memory
        // var_dump("SCS::getObject() to memory", $scs->getObject($bucketName, baseName($uploadFile)));
        // Or save it into a file (write stream)
        // var_dump("SCS::getObject() to savefile.txt", $scs->getObject($bucketName, baseName($uploadFile), 'savefile.txt'));
        // Or write it to a resource (write stream)
        // var_dump("SCS::getObject() to resource", $scs->getObject($bucketName, baseName($uploadFile), fopen('savefile.txt', 'wb')));
        // Get the access control policy for a bucket:
        // $acp = $scs->getAccessControlPolicy($bucketName);
        // echo "SCS::getAccessControlPolicy(): {$bucketName}: ".print_r($acp, 1);
        // Update an access control policy ($acp should be the same as the data returned by SCS::getAccessControlPolicy())
        // $scs->setAccessControlPolicy($bucketName, '', $acp);
Esempio n. 2
0
    /* 列出图片 */
    case 'listimage':
    default:
        $allowFiles = $CONFIG['imageManagerAllowFiles'];
        $listSize = $CONFIG['imageManagerListSize'];
        $path = $CONFIG['imageManagerListPath'];
}
$allowFiles = substr(str_replace(".", "|", join("", $allowFiles)), 1);
/* 获取参数 */
$size = isset($_GET['size']) ? htmlspecialchars($_GET['size']) : $listSize;
$start = isset($_GET['start']) ? htmlspecialchars($_GET['start']) : 0;
$end = $start + $size;
/* 获取文件列表 */
$scs = new SCS($accessKey, $secretKey);
//初始化新浪SCS
$get_filelist = SCS::getBucket($bucket);
//获取文件列表
foreach ($get_filelist as $value) {
    if ($_GET['action'] == 'listimage') {
        preg_match("/^upload\\/image\\/.*[{$allowFiles}]\$/", $value['name'], $urls);
    } else {
        if ($_GET['action'] == 'listfile') {
            preg_match("/^upload\\/file\\/.*[{$allowFiles}]\$/", $value['name'], $urls);
        }
    }
    if ($urls) {
        $files[] = array('url' => $bucket . "/" . $urls[0], 'mtime' => $value['time']);
    }
}
if (!count($files)) {
    return json_encode(array("state" => "no match file", "list" => array(), "start" => $start, "total" => count($files)));
Esempio n. 3
0
<?php

include "SCS.php";
include "config.php";
$scs = new SCS(AccessKey, SecretKey);
$bucketName = BUCKETNAME;
$contents = $scs->getBucket($bucketName, PREFIX);
$all_size = 0;
$index = 0;
foreach ($contents as $file) {
    $all_size += $file['size'];
    //var_dump($file);
    echo str_pad($index++ . ". " . $file['name'], 64, ".") . $file['size'] . "\n";
}
echo "All file size: " . $all_size . "\n";