@@ -610,18 +610,27 @@ public static function inputResource(&$resource, $bufferSize = false, $md5sum =
610
610
* @param array $requestHeaders Array of request headers or content type as a string
611
611
* @param constant $storageClass Storage class constant
612
612
* @param constant $serverSideEncryption Server-side encryption
613
+ * @param boolean $checkExistence Whether to check if the object was already there
613
614
* @return boolean
614
615
*/
615
- public static function putObject ($ input , $ bucket , $ uri , $ acl = self ::ACL_PRIVATE , $ metaHeaders = array (), $ requestHeaders = array (), $ storageClass = self ::STORAGE_CLASS_STANDARD , $ serverSideEncryption = self ::SSE_NONE )
616
+ 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 )
616
617
{
617
618
if ($ input === false ) return false ;
618
- $ rest = new S3Request ('PUT ' , $ bucket , $ uri , self ::$ endpoint );
619
619
620
620
if (!is_array ($ input )) $ input = array (
621
621
'data ' => $ input , 'size ' => strlen ($ input ),
622
622
'md5sum ' => base64_encode (md5 ($ input , true ))
623
623
);
624
624
625
+ if ($ checkExistence && isset ($ input ['md5sum ' ])) {
626
+ $ response = self ::getObjectInfo ($ bucket , $ uri );
627
+ if (isset ($ response ['hash ' ]) && bin2hex (base64_decode ($ input ['md5sum ' ])) == $ response ['hash ' ]) {
628
+ return true ;
629
+ }
630
+ }
631
+
632
+ $ rest = new S3Request ('PUT ' , $ bucket , $ uri , self ::$ endpoint );
633
+
625
634
// Data
626
635
if (isset ($ input ['fp ' ]))
627
636
$ rest ->fp =& $ input ['fp ' ];
0 commit comments