/**
  *	Deletes photos that are in S3 but paths not in SimpleDB
  *
  *	When a business is updated, all the photos are uploaded again to S3. The
  *	name of those photos might be different or the same even if the user
  *	hasn't added/removed any photos. This might lead to problems like there
  *	are photos in S3 whose paths aren't in SimpleDB. To circumvent this,
  *	before saving a business data that is being edited, all photos in S3
  *	which aren't in the Simple DB are deleted. 
  *
  *	@param $old_photo_url_array Photo URL of photos before business data 
  *															is updated in SimpleDB
  *	@param $new_photo_url_array Photo URL of photos that are to be updated
  *															in S3	
  */
 public static function delete($old_photo_url_array, $new_photo_url_array)
 {
     $to_delete_photo_url_array = array_diff($old_photo_url_array, $new_photo_url_array);
     //If there is no diff, there is no need of deleting
     if (empty($to_delete_photo_url_array) === TRUE) {
         return;
     }
     S3Persister::batch_delete($to_delete_photo_url_array);
 }
 /**
  * Deletes a bunch of objects in S3
  *
  *	@param $object_array The paths of the objects inside the bucket
  */
 public static function batch_delete($object_array)
 {
     S3Persister::init();
     $client = S3Client::factory(array('key' => S3Persister::$AWS_KEY, 'secret' => S3Persister::$AWS_SECRET_KEY, 'region' => S3Persister::REGION));
     $bucket = S3Persister::$BUCKET_NAME;
     $delete_objects = array();
     foreach ($object_array as $object) {
         //$object_path = "{$bucket}/{$object}";
         array_push($delete_objects, array("Key" => $object));
     }
     $request = $client->deleteObjects(array('Bucket' => "{$bucket}", 'Objects' => $delete_objects));
     return TRUE;
 }
<?php

require_once "config.php";
use citibytes\Watermark;
use citibytes\persister\S3Persister;
use citibytes\exceptions\WatermarkException;
$uploaded_file_path = $_FILES['file']['tmp_name'];
$file_name = $_POST['file_path'];
try {
    $watermark = new Watermark();
    $watermark->addWatermark($uploaded_file_path);
} catch (WatermarkException $e) {
    error_log($e->getMessage());
    $result_json = array("status" => "error", "error" => "Error occured while applying watermark");
    echo json_encode($result_json);
    exit;
}
$result = S3Persister::put($uploaded_file_path, $file_name);
if ($result === TRUE) {
    $result_json = array("status" => "ok", "file_path" => $file_name);
} else {
    $result_json = array("status" => "error", "error" => "Please Try Again Later");
}
echo json_encode($result_json);
<?php

require_once "config.php";
use citibytes\BusinessDetails;
use citibytes\persister\S3Persister;
$business_id = $_REQUEST["business_id"];
$business_details = new BusinessDetails();
$output = $business_details->get($business_id);
/**
 * Hours of operation is stored as a JSON string in SimpleDB.
 * Coverting the JSON string into PHP Array
 */
$hours_of_operation = $output["hours_of_operation"];
$hours_of_operation = json_decode($hours_of_operation, TRUE);
$output["hours_of_operation"] = $hours_of_operation;
//Generate URLs for client to download photo data from S3
$photo_url_array = $output["photo_url"];
foreach ($photo_url_array as $index => $photo_url) {
    $url = S3Persister::getPresignedURL($photo_url, "+10 minutes");
    $photo_url_array[$index] = $url;
}
$output["photo_url"] = $photo_url_array;
echo json_encode($output);