Пример #1
0
 *       http://aws.amazon.com/apache2.0/
 *
 * or in the "license.txt" file accompanying this file. This file is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the
 * License.
 */
error_reporting(E_ALL);
require_once 'sdk.class.php';
require_once 'include/book.inc.php';
// Make sure that some arguments were supplied
if ($argc < 3) {
    exit("Usage: " . $argv[0] . " bucket files...\n");
}
// Get Bucket argument
$bucket = $argv[1] == '-' ? BOOK_BUCKET : $argv[1];
// Create the S3 access object
$s3 = new AmazonS3();
// Upload each file
for ($i = 2; $i < $argc; $i++) {
    $file = $argv[$i];
    $data = file_get_contents($file);
    $contentType = guessType($file);
    if (uploadObject($s3, $bucket, $file, $data, AmazonS3::ACL_PUBLIC, $contentType)) {
        print "Uploaded file '{$file}' " . "to bucket '{$bucket}'\n";
    } else {
        exit("Could not " . "upload file '{$file}' " . "to bucket '{$bucket}'\n");
    }
}
exit(0);
$bucketOut = $argv[2] == '-' ? $bucketIn . THUMB_BUCKET_SUFFIX : $argv[2];
// Confirm intent
print "Thumbnailing '{$bucketIn}' to '{$bucketOut}'\n";
// Create the S3 access object
$s3 = new AmazonS3();
// Get object list from input bucket
$objectsIn = getBucketObjects($s3, $bucketIn);
// Process each object. Generate thumbnails only for images
foreach ($objectsIn as $objectIn) {
    $key = $objectIn->Key;
    print "Processing item '{$key}':\n";
    if (substr(guessType($key), 0, 6) == "image/") {
        $startTime = microtime(true);
        $dataIn = $s3->get_object($bucketIn, $key);
        $endTime = microtime(true);
        $contentType = guessType($key);
        printf("\tDownloaded from S3 in %.2f seconds.\n", $endTime - $startTime);
        $startTime = microtime(true);
        $dataOut = thumbnailImage($dataIn->body, $contentType);
        $endTime = microtime(true);
        printf("\tGenerated thumbnail in %.2f seconds.\n", $endTime - $startTime);
        $startTime = microtime(true);
        if (uploadObject($s3, $bucketOut, $key, $dataOut, AmazonS3::ACL_PUBLIC, $contentType)) {
            $endTime = microtime(true);
            printf("\tUploaded thumbnail to S3 in %.2f seconds.\n", $endTime - $startTime);
        } else {
            print "\tCould not upload thumbnail.\n";
        }
    } else {
        print "\tSkipping - not an image\n";
    }
Пример #3
0
 /**
  * Loads all items from an array
  *
  * @param $array (mixed array)
  * @public
  */
 function loadConfigArray($array)
 {
     foreach ($array as $name => $value) {
         $type = guessType($value);
         if (!isError($type)) {
             $item = new configItem($name, $type);
             $item->setValue($value);
             $this->addOption($item);
         } else {
             return $type;
         }
     }
 }