Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds option to putObject() to check if the object was already there #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,18 +610,27 @@ public static function inputResource(&$resource, $bufferSize = false, $md5sum =
* @param array $requestHeaders Array of request headers or content type as a string
* @param constant $storageClass Storage class constant
* @param constant $serverSideEncryption Server-side encryption
* @param boolean $checkExistence Whether to check if the object was already there
* @return boolean
*/
public static function putObject($input, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array(), $storageClass = self::STORAGE_CLASS_STANDARD, $serverSideEncryption = self::SSE_NONE)
public static function putObject($input, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array(), $storageClass = self::STORAGE_CLASS_STANDARD, $serverSideEncryption = self::SSE_NONE, $checkExistence = false)
{
if ($input === false) return false;
$rest = new S3Request('PUT', $bucket, $uri, self::$endpoint);

if (!is_array($input)) $input = array(
'data' => $input, 'size' => strlen($input),
'md5sum' => base64_encode(md5($input, true))
);

if ($checkExistence && isset($input['md5sum'])) {
$response = self::getObjectInfo($bucket, $uri);
if (isset($response['hash']) && bin2hex(base64_decode($input['md5sum'])) == $response['hash']) {
return true;
}
}

$rest = new S3Request('PUT', $bucket, $uri, self::$endpoint);

// Data
if (isset($input['fp']))
$rest->fp =& $input['fp'];
Expand Down