/**
  * Move a file or folder to a specific location
  *
  * @param string $from The location to move from
  * @param string $to The location to move to
  * @param string $point
  * @return boolean
  */
 public function moveObject($from, $to, $point = 'append')
 {
     $this->xpdo->lexicon->load('source');
     $success = false;
     if (substr(strrev($from), 0, 1) == '/') {
         $this->xpdo->error->message = $this->xpdo->lexicon('s3_no_move_folder', array('from' => $from));
         return $success;
     }
     if (!$this->driver->if_object_exists($this->bucket, $from)) {
         $this->xpdo->error->message = $this->xpdo->lexicon('file_err_ns') . ': ' . $from;
         return $success;
     }
     if ($to != '/') {
         if (!$this->driver->if_object_exists($this->bucket, $to)) {
             $this->xpdo->error->message = $this->xpdo->lexicon('file_err_ns') . ': ' . $to;
             return $success;
         }
         $toPath = rtrim($to, '/') . '/' . basename($from);
     } else {
         $toPath = basename($from);
     }
     $response = $this->driver->copy_object(array('bucket' => $this->bucket, 'filename' => $from), array('bucket' => $this->bucket, 'filename' => $toPath), array('acl' => AmazonS3::ACL_PUBLIC));
     $success = $response->isOK();
     if ($success) {
         $deleteResponse = $this->driver->delete_object($this->bucket, $from);
         $success = $deleteResponse->isOK();
     } else {
         $this->xpdo->error->message = $this->xpdo->lexicon('file_folder_err_rename') . ': ' . $to . ' -> ' . $from;
     }
     return $success;
 }
 /**
  * rename file/directory
  *
  * @return string
  */
 public function rename()
 {
     $oldPath = $this->sanitizePath($this->get['old']);
     $isDir = $this->isDir($this->metadata("{$oldPath}/"));
     $oldPath .= $isDir ? '/' : '';
     $contents = $isDir ? $this->s3->get_object_list($this->bucket, array('prefix' => $oldPath)) : array();
     // NOTE: we do this instead of isDir as we only care if there are files under this prefix
     if (count($contents) > 1) {
         $this->error('Unfortunately, we are currently unable to rename a non-empty directory.', false);
     }
     $pathInfo = pathinfo($oldPath);
     $dirName = $pathInfo['dirname'];
     $baseName = $pathInfo['basename'];
     $newFile = $this->get['new'];
     $newPath = join('/', array($dirName, $newFile));
     if ($isDir) {
         $response = $this->createDirectory($newPath);
     } else {
         $response = $this->s3->copy_object(array('bucket' => $this->bucket, 'filename' => $oldPath), array('bucket' => $this->bucket, 'filename' => $newPath), array('acl' => AmazonS3::ACL_PUBLIC));
     }
     if ($response->isOK()) {
         $this->s3->delete_object($this->bucket, $oldPath);
     }
     return array('Error' => '', 'Code' => 0, 'Old Path' => $oldPath, 'Old Name' => $baseName, 'New Path' => $newPath, 'New Name' => $newFile);
 }
示例#3
0
    exit;
}
$mime = NULL;
$response = $s3->get_object_metadata($bucket, $name);
//get content-type of existing object
if ($response) {
    $mime = $response["ContentType"];
}
if (empty($mime)) {
    printf("No mime found for object \n");
    exit;
}
$source = array("bucket" => $bucket, "filename" => $name);
$dest = array("bucket" => $bucket, "filename" => $name);
// caching headers
// expire after 365 days
$offset = 3600 * 24 * 365;
$expiresOn = gmdate('D, d M Y H:i:s \\G\\M\\T', time() + $offset);
$headers = array();
$headers["Expires"] = $expiresOn;
$headers["Cache-Control"] = "public, max-age=31536000";
$headers["Content-Type"] = $mime;
// This will overwrite existing headers
$meta = array('acl' => AmazonS3::ACL_PUBLIC, 'headers' => $headers);
$response = $s3->copy_object($source, $dest, $meta);
if ($response->isOk()) {
    printf("s3 object copy done \n");
} else {
    printf("Error :: s3 object copy \n");
    exit;
}
示例#4
0
 */
require_once "sdk-1.5.7/sdk.class.php";
error_reporting(-1);
$config = parse_ini_file("aws.ini");
$awsKey = $config["aws.key"];
$awsSecret = $config["aws.secret"];
$options = array("key" => $awsKey, "secret" => $awsSecret, "default_cache_config" => '', "certificate_authority" => true);
$s3 = new AmazonS3($options);
$source = "test.indigloo";
$target = "rjha";
$name = "polaroid.swf";
$exists = $s3->if_bucket_exists($source);
if (!$exists) {
    $message = sprintf("source bucket %s does not exists", $source);
    printf("%s \n", $message);
    exit;
}
$exists = $s3->if_bucket_exists($target);
if (!$exists) {
    $message = sprintf("target bucket %s does not exists", $source);
    printf("%s \n", $message);
    exit;
}
$source = array("bucket" => $source, "filename" => $name);
$dest = array("bucket" => $target, "filename" => $name);
$response = $s3->copy_object($source, $dest);
if ($response->isOk()) {
    printf("s3 object copy done \n");
} else {
    printf("Error :: s3 object copy \n");
}