예제 #1
0
<?php

include "SCS.php";
include "config.php";
if (count($argv) <= 1) {
    echo "ERROR\n";
    exit;
}
$ttl = isset($argv[2]) ? $argv[2] : 3600;
$scs = new SCS(AccessKey, SecretKey);
$uploadFile = $argv[1];
$bucketName = BUCKETNAME;
if (preg_match("/\\d+/", $uploadFile) > 0) {
    $m = k_run_time("files");
    $uploadFile = $m[$uploadFile]["name"];
}
$obj = SCS::getAuthenticatedURL($bucketName, $uploadFile, $ttl);
echo "DOWNLOAD URL IS : \n";
echo $obj . "\n";
//if (!extension_loaded('fileinfo') && @dl('fileinfo.so')) $_ENV['MAGIC'] = '/usr/share/file/magic';
// Check if our upload file exists
if (!file_exists($uploadFile) || !is_file($uploadFile)) {
    exit("\nERROR: No such file: {$uploadFile}\n\n");
}
// Check for CURL
if (!extension_loaded('curl') && !@dl(PHP_SHLIB_SUFFIX == 'so' ? 'curl.so' : 'php_curl.dll')) {
    exit("\nERROR: CURL extension not loaded\n\n");
}
// Pointless without your keys!
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