* 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. * * Modified by Jeffrey S. Haemer <*****@*****.**> */ error_reporting(E_ALL); require_once 'AWSSDKforPHP/sdk.class.php'; require_once 'include/book.inc.php'; // Create the SimpleDB access object $sdb = new AmazonSDB(); // Insert an entry for every PHP file in the current directory $dir = opendir("."); while (($file = readdir($dir)) !== false) { if (preg_match("/^[a-zA-Z0-9_-]*\\.php\$/", $file)) { $data = file_get_contents($file); $hash = md5($data); $size = filesize($file); $attrs = array('Name' => $file, 'Hash' => $hash, 'Size' => sprintf("%08s", $size)); $res = $sdb->put_attributes(BOOK_FILE_DOMAIN, $file, $attrs, true); if ($res->isOK()) { print "Inserted item {$file}\n"; } else { $error = $res->body->Errors->Error->Message; print "Could not insert item: {$error}\n"; } } } closedir($dir); exit(0);
<?php require_once '/usr/share/php/AWSSDKforPHP/sdk.class.php'; define('AWS_KEY', 'AKIAIGKECZXA7AEIJLMQ'); define('AWS_SECRET_KEY', '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'); define('AWS_ACCOUNT_ID', '457964863276'); # construct the message (use zero padding to handle # simpledb's lexicographic ordering) $account = array('fair' => 'yes', 'PDFs' => sprintf('%05d', '0')); $sdb = new AmazonSDB(); # $sdb->set_region($sdb::REGION_EU_W1); $accounts = $sdb->create_domain('accounts'); $accounts->isOK() or die('could not create domain accounts'); $response = $sdb->put_attributes('accounts', '*****@*****.**', $account, true); pr($response->body); function pr($var) { print '<pre>'; print_r($var); print '</pre>'; }
require_once '/usr/share/php/AWSSDKforPHP/sdk.class.php'; define('AWS_KEY', 'AKIAIGKECZXA7AEIJLMQ'); define('AWS_SECRET_KEY', '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'); define('AWS_ACCOUNT_ID', '457964863276'); # for testing the conditional put $timeout = isset($_GET['timeout']) ? (int) $_GET['timeout'] : 0; $sdb = new AmazonSDB(); # $sdb->set_region($sdb::REGION_EU_W1); $accounts = $sdb->create_domain('accounts'); $accounts->isOK() or die('could not create domain accounts'); # we have to be a bit persistent; even though it # is unlikely someone else might have incremented # during our operation do { $response = $sdb->get_attributes('accounts', '*****@*****.**', 'PDFs'); $PDFs = (int) $response->body->Value(0); # convenience measure for testing sleep($timeout); $account = array('PDFs' => sprintf('%05d', $PDFs + 1)); $response = $sdb->put_attributes('accounts', '*****@*****.**', $account, true, array('Expected.Name' => 'PDFs', 'Expected.Value' => sprintf('%05d', $PDFs))); } while ($response->isOK() === FALSE); # to read the value we have to force a consistent read $response = $sdb->get_attributes('accounts', '*****@*****.**', 'PDFs', array('ConsistentRead' => 'true')); pr((int) $response->body->Value(0)); function pr($var) { print '<pre>'; print_r($var); print '</pre>'; }
*/ error_reporting(E_ALL); require_once 'AWSSDKforPHP/sdk.class.php'; require_once 'include/book.inc.php'; // Create the SimpleDB access object $sdb = new AmazonSDB(); // Query for each file $res1 = $sdb->select("select Name from " . BOOK_FILE_DOMAIN); if ($res1->isOK()) { foreach ($res1->body->SelectResult->Item as $item) { $itemName = $item->Name; $file = $item->Attribute[0]->Value; $modTime = filemtime($file); if ($modTime !== false) { $attrs = array('ModTime' => sprintf("%010s", $modTime)); $attrs2 = array('Flavors' => array('Vanilla', 'Chocolate')); $res2 = $sdb->put_attributes(BOOK_FILE_DOMAIN, $itemName, $attrs, false); $res2 = $sdb->put_attributes(BOOK_FILE_DOMAIN, $itemName, $attrs2, false); if ($res2->isOK()) { print "Updated item {$itemName}\n"; } else { $error = $res2->body->Errors->Error->Message; print "Could not update item: {$error}\n"; } } } } else { $error = $res1->body->Errors->Error->Message; exit("Could not run query: {$error}\n"); } exit(0);
* 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. * * Modified by Jeffrey S. Haemer <*****@*****.**> */ error_reporting(E_ALL); require_once 'AWSSDKforPHP/sdk.class.php'; require_once 'include/cloudfunctions.inc.php'; // Check arguments if ($argc < 3) { exit("Usage: " . $argv[0] . " CITY STATE\n"); } // Get city and state $city = $argv[1]; $state = $argv[2]; // Form key $key = $state . '_' . $city; // Form attributes $attrs = array('City' => $city, 'State' => $state); // Create access object $sdb = new AmazonSDB(); // Insert item $res = $sdb->put_attributes(CL_CITY_DOMAIN, $key, $attrs, true); if ($res->isOK()) { print "Added city {$city} in {$state}\n"; } else { $error = $res->body->Errors->Error->Message; print "Could not add city: {$error}\n"; }
<?php require_once './sdk.class.php'; error_reporting(-1); ini_set('display_errors', true); header("Content-type: text/html; charset=utf-8"); $sdb = new AmazonSDB(); $domain = 'authors'; $uname = $_POST["name"]; $email = $_POST["email"]; $pass = $_POST["pass"]; $type = $_POST["type"] == "Reader" ? "2" : "1"; //reader->2 author->1 if ($uname && $email && $pass) { $response = $sdb->get_attributes($domain, $email); if ($response->body->GetAttributesResult->Attribute) { echo "already registered"; } else { $response = $sdb->put_attributes($domain, $email, array('name' => $uname, 'password' => md5($pass), 'type' => $type)); if ($response->isOK()) { session_start(); $_SESSION['ucmsg'] = "User created."; } else { session_start(); $_SESSION['uemsg'] = "User creation failed."; } header('Location:admin.php'); } }
/*%******************************************************************************************%*/ // ADD DATA TO SIMPLEDB // Instantiate the AmazonSDB class $sdb = new AmazonSDB(); // Store the name of the domain $domain = 'php-sdk-getting-started'; // Create the domain $new_domain = $sdb->create_domain($domain); // Was the domain created successfully? if ($new_domain->isOK()) { // Add a batch of item-key-values to your domain $add_attributes = $sdb->batch_put_attributes($domain, array('Item_01' => array('Category' => 'Clothes', 'Subcategory' => 'Sweater', 'Name' => 'Cathair Sweater', 'Color' => 'Siamese', 'Size' => array('Small', 'Medium', 'Large')), 'Item_02' => array('Category' => 'Clothes', 'Subcategory' => 'Pants', 'Name' => 'Designer Jeans', 'Color' => 'Paisley Acid Wash', 'Size' => array('30x32', '32x32', '32x34')), 'Item_03' => array('Category' => 'Clothes', 'Subcategory' => 'Pants', 'Name' => 'Sweatpants', 'Color' => array('Blue', 'Yellow', 'Pink'), 'Size' => 'Large', 'Year' => array('2006', '2007')), 'Item_04' => array('Category' => 'Car Parts', 'Subcategory' => 'Engine', 'Name' => 'Turbos', 'Make' => 'Audi', 'Model' => 'S4', 'Year' => array('2000', '2001', '2002')), 'Item_05' => array('Category' => 'Car Parts', 'Subcategory' => 'Emissions', 'Name' => 'O2 Sensor', 'Make' => 'Audi', 'Model' => 'S4', 'Year' => array('2000', '2001', '2002')))); // Were the attributes added successfully? if ($add_attributes->isOK()) { // Add an additional size to Item_01 $append_attributes = $sdb->put_attributes($domain, 'Item_01', array('Size' => 'Extra Large')); // Were the new attributes appended successfully? if ($append_attributes->isOK()) { // Use a SELECT expression to query the data. // Notice the use of backticks around the domain name. $results = $sdb->select("SELECT * FROM `{$domain}` WHERE Category = 'Clothes'"); // Get all of the <Item> nodes in the response $items = $results->body->Item(); // Re-structure the data so access is easier (see helper function below) $data = reorganize_data($items); // Generate <table> HTML from the data (see helper function below) $html = generate_html_table($data); } } } /*%******************************************************************************************%*/
<?php require_once './sdk.class.php'; $s3 = new AmazonS3(); $bucket = 'book-bucket-' . strtolower($s3->key); $response1 = $s3->create_object($bucket, $_FILES['uploadedfile']['name'], array('fileUpload' => $_FILES['uploadedfile']['tmp_name'], 'acl' => AmazonS3::ACL_PUBLIC, 'meta' => array('title' => $_POST['title']))); session_start(); $author = $_SESSION['email']; $book = $_POST['title']; $key = $author . '/' . $book; $domain = 'books-aalr'; $sdb = new AmazonSDB(); $response2 = $sdb->put_attributes($domain, $key, array('author' => $author, 'title' => $book)); //var_dump($_FILES); //var_dump($response); //var_dump($response->body) if ($response1->isOK() && $response2->isOK()) { session_start(); $_SESSION['upmsg'] = "Upload successful"; header('Location:author.php'); } else { session_start(); $_SESSION['upemsg'] = "Upload failed"; header('Location:author.php'); }
* specific language governing permissions and limitations under the * License. * * Modified by Jeffrey S. Haemer <*****@*****.**> */ error_reporting(E_ALL); require_once 'AWSSDKforPHP/sdk.class.php'; require_once 'include/book.inc.php'; // Check arguments if ($argc < 3) { exit("Usage: " . $argv[0] . " \"message\" VOLUMEID...\n"); } // Get message $message = $argv[1]; // Create access objects $sdb = new AmazonSDB(); $ec2 = new AmazonEC2(); // Process each volume for ($i = 2; $i < $argc; $i++) { $volId = $argv[$i]; // Create snapshot $res1 = $ec2->create_snapshot($volId, "{$volId}: {$message}"); if ($res1->isOK()) { $snapId = $res1->body->snapshotId; $startTime = $res1->body->startTime; $key = $volId . '_' . $startTime; $attrs = array('VolId' => $volId, 'Message' => $message, 'StartTime' => $startTime); $res2 = $sdb->put_attributes(BOOK_SNAP_LOG_DOMAIN, $key, $attrs, true); } } exit(0);