Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../includes
File: S3.php
if (false === $rest->error && 204 !== $rest->code) {
[500] Fix | Delete
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
[501] Fix | Delete
}
[502] Fix | Delete
[503] Fix | Delete
if (false !== $rest->error) {
[504] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::deleteBucket({$bucket}): [%s] %s",
[505] Fix | Delete
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
[506] Fix | Delete
return false;
[507] Fix | Delete
}
[508] Fix | Delete
return true;
[509] Fix | Delete
}
[510] Fix | Delete
[511] Fix | Delete
[512] Fix | Delete
/**
[513] Fix | Delete
* Create input info array for putObject()
[514] Fix | Delete
*
[515] Fix | Delete
* @param string $file Input file
[516] Fix | Delete
* @param mixed $md5sum Use MD5 hash (supply a string if you want to use your own)
[517] Fix | Delete
* @return array | false
[518] Fix | Delete
*/
[519] Fix | Delete
public function inputFile($file, $md5sum = true) {
[520] Fix | Delete
if (!file_exists($file) || !is_file($file) || !is_readable($file)) {
[521] Fix | Delete
$this->__triggerError('UpdraftPlus_S3::inputFile(): Unable to open input file: '.$file, __FILE__, __LINE__);
[522] Fix | Delete
return false;
[523] Fix | Delete
}
[524] Fix | Delete
return array('file' => $file, 'size' => filesize($file), 'md5sum' => $md5sum !== false ?
[525] Fix | Delete
(is_string($md5sum) ? $md5sum : base64_encode(md5_file($file, true))) : '', 'sha256sum' => hash_file('sha256', $file));
[526] Fix | Delete
}
[527] Fix | Delete
[528] Fix | Delete
[529] Fix | Delete
/**
[530] Fix | Delete
* Create input array info for putObject() with a resource
[531] Fix | Delete
*
[532] Fix | Delete
* @param string $resource Input resource to read from
[533] Fix | Delete
* @param integer $bufferSize Input byte size
[534] Fix | Delete
* @param string $md5sum MD5 hash to send (optional)
[535] Fix | Delete
* @return array | false
[536] Fix | Delete
*/
[537] Fix | Delete
public function inputResource(&$resource, $bufferSize, $md5sum = '') {
[538] Fix | Delete
if (!is_resource($resource) || $bufferSize < 0) {
[539] Fix | Delete
$this->__triggerError('UpdraftPlus_S3::inputResource(): Invalid resource or buffer size', __FILE__, __LINE__);
[540] Fix | Delete
return false;
[541] Fix | Delete
}
[542] Fix | Delete
$input = array('size' => $bufferSize, 'md5sum' => $md5sum);
[543] Fix | Delete
$input['fp'] =& $resource;
[544] Fix | Delete
return $input;
[545] Fix | Delete
}
[546] Fix | Delete
[547] Fix | Delete
/**
[548] Fix | Delete
* Initiate a multi-part upload (http://docs.amazonwebservices.com/AmazonS3/latest/API/mpUploadInitiate.html)
[549] Fix | Delete
*
[550] Fix | Delete
* @param string $bucket Bucket name
[551] Fix | Delete
* @param string $uri Object URI
[552] Fix | Delete
* @param string $acl ACL constant
[553] Fix | Delete
* @param array $metaHeaders Array of x-amz-meta-* headers
[554] Fix | Delete
* @param array $requestHeaders Array of request headers or content type as a string
[555] Fix | Delete
* @param string $storageClass Storage class constant
[556] Fix | Delete
*
[557] Fix | Delete
* @return string | false
[558] Fix | Delete
*/
[559] Fix | Delete
public function initiateMultipartUpload ($bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array(), $storageClass = self::STORAGE_CLASS_STANDARD) {
[560] Fix | Delete
[561] Fix | Delete
$rest = new UpdraftPlus_S3Request('POST', $bucket, $uri, $this->endpoint, $this->use_dns_bucket_name, $this);
[562] Fix | Delete
$rest->setParameter('uploads','');
[563] Fix | Delete
[564] Fix | Delete
// Custom request headers (Content-Type, Content-Disposition, Content-Encoding)
[565] Fix | Delete
if (is_array($requestHeaders))
[566] Fix | Delete
foreach ($requestHeaders as $h => $v) $rest->setHeader($h, $v);
[567] Fix | Delete
[568] Fix | Delete
// Set storage class
[569] Fix | Delete
if ($storageClass !== self::STORAGE_CLASS_STANDARD) // Storage class
[570] Fix | Delete
$rest->setAmzHeader('x-amz-storage-class', $storageClass);
[571] Fix | Delete
[572] Fix | Delete
// Set ACL headers
[573] Fix | Delete
$rest->setAmzHeader('x-amz-acl', $acl);
[574] Fix | Delete
foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v);
[575] Fix | Delete
[576] Fix | Delete
// Carry out the HTTP operation
[577] Fix | Delete
$rest->getResponse();
[578] Fix | Delete
[579] Fix | Delete
if (false === $rest->response->error && 200 !== $rest->response->code) {
[580] Fix | Delete
$rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
[581] Fix | Delete
}
[582] Fix | Delete
[583] Fix | Delete
if (false !== $rest->response->error) {
[584] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::initiateMultipartUpload(): [%s] %s",
[585] Fix | Delete
$rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__);
[586] Fix | Delete
return false;
[587] Fix | Delete
} elseif (isset($rest->response->body)) {
[588] Fix | Delete
// DreamObjects already returns a SimpleXMLElement here. Not sure how that works.
[589] Fix | Delete
if (is_a($rest->response->body, 'SimpleXMLElement')) {
[590] Fix | Delete
$body = $rest->response->body;
[591] Fix | Delete
} else {
[592] Fix | Delete
$body = new SimpleXMLElement($rest->response->body);
[593] Fix | Delete
}
[594] Fix | Delete
return (string) $body->UploadId;
[595] Fix | Delete
}
[596] Fix | Delete
[597] Fix | Delete
// It is a programming error if we reach this line
[598] Fix | Delete
return false;
[599] Fix | Delete
[600] Fix | Delete
}
[601] Fix | Delete
[602] Fix | Delete
/**
[603] Fix | Delete
* Upload a part of a multi-part set (http://docs.amazonwebservices.com/AmazonS3/latest/API/mpUploadUploadPart.html)
[604] Fix | Delete
* The chunk is read into memory, so make sure that you have enough (or patch this function to work another way!)
[605] Fix | Delete
*
[606] Fix | Delete
* @param string $bucket Bucket name
[607] Fix | Delete
* @param string $uri Object URI
[608] Fix | Delete
* @param string $uploadId uploadId returned previously from initiateMultipartUpload
[609] Fix | Delete
* @param integer $partNumber sequential part number to upload
[610] Fix | Delete
* @param string $filePath file to upload content from
[611] Fix | Delete
* @param integer $partSize number of bytes in each part (though final part may have fewer) - pass the same value each time (for this particular upload) - default 5Mb (which is Amazon's minimum)
[612] Fix | Delete
* @return string (ETag) | false
[613] Fix | Delete
*/
[614] Fix | Delete
public function uploadPart ($bucket, $uri, $uploadId, $filePath, $partNumber, $partSize = 5242880) {
[615] Fix | Delete
[616] Fix | Delete
$rest = new UpdraftPlus_S3Request('PUT', $bucket, $uri, $this->endpoint, $this->use_dns_bucket_name, $this);
[617] Fix | Delete
$rest->setParameter('partNumber', $partNumber);
[618] Fix | Delete
$rest->setParameter('uploadId', $uploadId);
[619] Fix | Delete
[620] Fix | Delete
// Where to begin
[621] Fix | Delete
$fileOffset = ($partNumber - 1 ) * $partSize;
[622] Fix | Delete
[623] Fix | Delete
// Download the smallest of the remaining bytes and the part size
[624] Fix | Delete
$fileBytes = min(filesize($filePath) - $fileOffset, $partSize);
[625] Fix | Delete
if ($fileBytes < 0) $fileBytes = 0;
[626] Fix | Delete
[627] Fix | Delete
$rest->setHeader('Content-Type', 'application/octet-stream');
[628] Fix | Delete
$rest->data = "";
[629] Fix | Delete
[630] Fix | Delete
if ($handle = fopen($filePath, "rb")) {
[631] Fix | Delete
if ($fileOffset >0) fseek($handle, $fileOffset);
[632] Fix | Delete
$bytes_read = 0;
[633] Fix | Delete
while ($fileBytes>0 && $read = fread($handle, max($fileBytes, 131072))) {
[634] Fix | Delete
$fileBytes = $fileBytes - strlen($read);
[635] Fix | Delete
$bytes_read += strlen($read);
[636] Fix | Delete
$rest->data = $rest->data . $read;
[637] Fix | Delete
}
[638] Fix | Delete
fclose($handle);
[639] Fix | Delete
} else {
[640] Fix | Delete
return false;
[641] Fix | Delete
}
[642] Fix | Delete
[643] Fix | Delete
$rest->setHeader('Content-MD5', base64_encode(md5($rest->data, true)));
[644] Fix | Delete
$rest->size = $bytes_read;
[645] Fix | Delete
[646] Fix | Delete
$rest = $rest->getResponse();
[647] Fix | Delete
if (false === $rest->error && 200 !== $rest->code) {
[648] Fix | Delete
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
[649] Fix | Delete
}
[650] Fix | Delete
[651] Fix | Delete
if (false !== $rest->error) {
[652] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::uploadPart(): [%s] %s",
[653] Fix | Delete
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
[654] Fix | Delete
return false;
[655] Fix | Delete
}
[656] Fix | Delete
return $rest->headers['hash'];
[657] Fix | Delete
}
[658] Fix | Delete
[659] Fix | Delete
/**
[660] Fix | Delete
* Complete a multi-part upload (http://docs.amazonwebservices.com/AmazonS3/latest/API/mpUploadComplete.html)
[661] Fix | Delete
*
[662] Fix | Delete
* @param string $bucket Bucket name
[663] Fix | Delete
* @param string $uri Object URI
[664] Fix | Delete
* @param string $uploadId uploadId returned previously from initiateMultipartUpload
[665] Fix | Delete
* @param array $parts an ordered list of eTags of previously uploaded parts from uploadPart
[666] Fix | Delete
* @return boolean
[667] Fix | Delete
*/
[668] Fix | Delete
public function completeMultipartUpload($bucket, $uri, $uploadId, $parts) {
[669] Fix | Delete
$rest = new UpdraftPlus_S3Request('POST', $bucket, $uri, $this->endpoint, $this->use_dns_bucket_name, $this);
[670] Fix | Delete
$rest->setParameter('uploadId', $uploadId);
[671] Fix | Delete
[672] Fix | Delete
$xml = "<CompleteMultipartUpload>\n";
[673] Fix | Delete
$partno = 1;
[674] Fix | Delete
foreach ($parts as $etag) {
[675] Fix | Delete
$xml .= "<Part><PartNumber>$partno</PartNumber><ETag>$etag</ETag></Part>\n";
[676] Fix | Delete
$partno++;
[677] Fix | Delete
}
[678] Fix | Delete
$xml .= "</CompleteMultipartUpload>";
[679] Fix | Delete
[680] Fix | Delete
$rest->data = $xml;
[681] Fix | Delete
$rest->size = strlen($rest->data);
[682] Fix | Delete
$rest->setHeader('Content-Type', 'application/xml');
[683] Fix | Delete
[684] Fix | Delete
$rest = $rest->getResponse();
[685] Fix | Delete
if (false === $rest->error && 200 !== $rest->code) {
[686] Fix | Delete
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
[687] Fix | Delete
}
[688] Fix | Delete
[689] Fix | Delete
if (false !== $rest->error) {
[690] Fix | Delete
// Special case: when the error means "you've already done that". Turn it into success. See in: https://trello.com/c/6jJoiCG5
[691] Fix | Delete
if ('InternalError' == $rest->error['code'] && 'This multipart completion is already in progress' == $rest->error['message']) {
[692] Fix | Delete
return true;
[693] Fix | Delete
}
[694] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::completeMultipartUpload(): [%s] %s",
[695] Fix | Delete
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
[696] Fix | Delete
return false;
[697] Fix | Delete
}
[698] Fix | Delete
return true;
[699] Fix | Delete
[700] Fix | Delete
}
[701] Fix | Delete
[702] Fix | Delete
/**
[703] Fix | Delete
* Abort a multi-part upload (http://docs.amazonwebservices.com/AmazonS3/latest/API/mpUploadAbort.html)
[704] Fix | Delete
*
[705] Fix | Delete
* @param string $bucket Bucket name
[706] Fix | Delete
* @param string $uri Object URI
[707] Fix | Delete
* @param string $uploadId uploadId returned previously from initiateMultipartUpload
[708] Fix | Delete
* @return boolean
[709] Fix | Delete
*/
[710] Fix | Delete
// TODO: From this line
[711] Fix | Delete
public function abortMultipartUpload ($bucket, $uri, $uploadId) {
[712] Fix | Delete
$rest = new UpdraftPlus_S3Request('DELETE', $bucket, $uri, $this->endpoint, $this->use_dns_bucket_name, $this);
[713] Fix | Delete
$rest->setParameter('uploadId', $uploadId);
[714] Fix | Delete
$rest = $rest->getResponse();
[715] Fix | Delete
if (false === $rest->error && 204 !== $rest->code) {
[716] Fix | Delete
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
[717] Fix | Delete
}
[718] Fix | Delete
[719] Fix | Delete
if (false !== $rest->error) {
[720] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::abortMultipartUpload(): [%s] %s",
[721] Fix | Delete
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
[722] Fix | Delete
return false;
[723] Fix | Delete
}
[724] Fix | Delete
return true;
[725] Fix | Delete
}
[726] Fix | Delete
[727] Fix | Delete
/**
[728] Fix | Delete
* Put an object
[729] Fix | Delete
*
[730] Fix | Delete
* @param mixed $input Input data
[731] Fix | Delete
* @param string $bucket Bucket name
[732] Fix | Delete
* @param string $uri Object URI
[733] Fix | Delete
* @param string $acl ACL constant
[734] Fix | Delete
* @param array $metaHeaders Array of x-amz-meta-* headers
[735] Fix | Delete
* @param array $requestHeaders Array of request headers or content type as a string
[736] Fix | Delete
* @param string $storageClass Storage class constant
[737] Fix | Delete
*
[738] Fix | Delete
* @return boolean
[739] Fix | Delete
*/
[740] Fix | Delete
public function putObject($input, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array(), $storageClass = self::STORAGE_CLASS_STANDARD) {
[741] Fix | Delete
if ($input === false) return false;
[742] Fix | Delete
$rest = new UpdraftPlus_S3Request('PUT', $bucket, $uri, $this->endpoint, $this->use_dns_bucket_name, $this);
[743] Fix | Delete
[744] Fix | Delete
if (!is_array($input)) $input = array(
[745] Fix | Delete
'data' => $input, 'size' => strlen($input),
[746] Fix | Delete
'md5sum' => base64_encode(md5($input, true)),
[747] Fix | Delete
'sha256sum' => hash('sha256', $input)
[748] Fix | Delete
);
[749] Fix | Delete
[750] Fix | Delete
// Data
[751] Fix | Delete
if (isset($input['fp']))
[752] Fix | Delete
$rest->fp =& $input['fp'];
[753] Fix | Delete
elseif (isset($input['file']) && is_file($input['file']))
[754] Fix | Delete
$rest->fp = @fopen($input['file'], 'rb');
[755] Fix | Delete
elseif (isset($input['data']))
[756] Fix | Delete
$rest->data = $input['data'];
[757] Fix | Delete
[758] Fix | Delete
// Content-Length (required)
[759] Fix | Delete
if (isset($input['size']) && $input['size'] >= 0) {
[760] Fix | Delete
$rest->size = $input['size'];
[761] Fix | Delete
} else {
[762] Fix | Delete
if (isset($input['file']))
[763] Fix | Delete
$rest->size = filesize($input['file']);
[764] Fix | Delete
elseif (isset($input['data']))
[765] Fix | Delete
$rest->size = strlen($input['data']);
[766] Fix | Delete
}
[767] Fix | Delete
[768] Fix | Delete
// Custom request headers (Content-Type, Content-Disposition, Content-Encoding)
[769] Fix | Delete
if (is_array($requestHeaders))
[770] Fix | Delete
foreach ($requestHeaders as $h => $v) $rest->setHeader($h, $v);
[771] Fix | Delete
elseif (is_string($requestHeaders)) // Support for legacy contentType parameter
[772] Fix | Delete
$input['type'] = $requestHeaders;
[773] Fix | Delete
[774] Fix | Delete
// Content-Type
[775] Fix | Delete
if (!isset($input['type'])) {
[776] Fix | Delete
if (isset($requestHeaders['Content-Type']))
[777] Fix | Delete
$input['type'] =& $requestHeaders['Content-Type'];
[778] Fix | Delete
elseif (isset($input['file']))
[779] Fix | Delete
$input['type'] = $this->__getMimeType($input['file']);
[780] Fix | Delete
else
[781] Fix | Delete
$input['type'] = 'application/octet-stream';
[782] Fix | Delete
}
[783] Fix | Delete
[784] Fix | Delete
if ($storageClass !== self::STORAGE_CLASS_STANDARD) // Storage class
[785] Fix | Delete
$rest->setAmzHeader('x-amz-storage-class', $storageClass);
[786] Fix | Delete
[787] Fix | Delete
if (!empty($this->_serverSideEncryption)) {
[788] Fix | Delete
$rest->setAmzHeader('x-amz-server-side-encryption', $this->_serverSideEncryption);
[789] Fix | Delete
}
[790] Fix | Delete
// We need to post with Content-Length and Content-Type, MD5 is optional
[791] Fix | Delete
if ($rest->size >= 0 && (false !== $rest->fp || false !== $rest->data)) {
[792] Fix | Delete
$rest->setHeader('Content-Type', $input['type']);
[793] Fix | Delete
if (isset($input['md5sum'])) $rest->setHeader('Content-MD5', $input['md5sum']);
[794] Fix | Delete
[795] Fix | Delete
if (isset($input['sha256sum'])) $rest->setAmzHeader('x-amz-content-sha256', $input['sha256sum']);
[796] Fix | Delete
[797] Fix | Delete
$rest->setAmzHeader('x-amz-acl', $acl);
[798] Fix | Delete
foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v);
[799] Fix | Delete
$rest->getResponse();
[800] Fix | Delete
} else {
[801] Fix | Delete
$rest->response->error = array('code' => 0, 'message' => 'Missing input parameters');
[802] Fix | Delete
}
[803] Fix | Delete
[804] Fix | Delete
if (false === $rest->response->error && 200 !== $rest->response->code) {
[805] Fix | Delete
$rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
[806] Fix | Delete
}
[807] Fix | Delete
[808] Fix | Delete
if (false !== $rest->response->error) {
[809] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::putObject(): [%s] %s",
[810] Fix | Delete
$rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__);
[811] Fix | Delete
return false;
[812] Fix | Delete
}
[813] Fix | Delete
return true;
[814] Fix | Delete
}
[815] Fix | Delete
[816] Fix | Delete
[817] Fix | Delete
/**
[818] Fix | Delete
* Put an object from a file (legacy function)
[819] Fix | Delete
*
[820] Fix | Delete
* @param string $file Input file path
[821] Fix | Delete
* @param string $bucket Bucket name
[822] Fix | Delete
* @param string $uri Object URI
[823] Fix | Delete
* @param string $acl ACL constant
[824] Fix | Delete
* @param array $metaHeaders Array of x-amz-meta-* headers
[825] Fix | Delete
* @param string $contentType Content type
[826] Fix | Delete
* @param string $storageClass
[827] Fix | Delete
*
[828] Fix | Delete
* @return boolean
[829] Fix | Delete
*/
[830] Fix | Delete
public function putObjectFile($file, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = null, $storageClass = self::STORAGE_CLASS_STANDARD) {
[831] Fix | Delete
return $this->putObject($this->inputFile($file), $bucket, $uri, $acl, $metaHeaders, $contentType, $storageClass);
[832] Fix | Delete
}
[833] Fix | Delete
[834] Fix | Delete
/**
[835] Fix | Delete
* Put an object from a string (legacy function)
[836] Fix | Delete
*
[837] Fix | Delete
* @param string $string Input data
[838] Fix | Delete
* @param string $bucket Bucket name
[839] Fix | Delete
* @param string $uri Object URI
[840] Fix | Delete
* @param string $acl ACL constant
[841] Fix | Delete
* @param array $metaHeaders Array of x-amz-meta-* headers
[842] Fix | Delete
* @param string $contentType Content type
[843] Fix | Delete
* @return boolean
[844] Fix | Delete
*/
[845] Fix | Delete
public function putObjectString($string, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = 'text/plain') {
[846] Fix | Delete
return $this->putObject($string, $bucket, $uri, $acl, $metaHeaders, $contentType);
[847] Fix | Delete
}
[848] Fix | Delete
[849] Fix | Delete
/**
[850] Fix | Delete
* Get an object
[851] Fix | Delete
*
[852] Fix | Delete
* @param string $bucket Bucket name
[853] Fix | Delete
* @param string $uri Object URI
[854] Fix | Delete
* @param mixed $saveTo Filename or resource to write to
[855] Fix | Delete
* @param mixed $resume - if $saveTo is a resource, then this is either false or the value for a Range: header; otherwise, a boolean, indicating whether to resume if possible.
[856] Fix | Delete
* @return mixed
[857] Fix | Delete
*/
[858] Fix | Delete
public function getObject($bucket, $uri, $saveTo = false, $resume = false) {
[859] Fix | Delete
$rest = new UpdraftPlus_S3Request('GET', $bucket, $uri, $this->endpoint, $this->use_dns_bucket_name, $this);
[860] Fix | Delete
if (false !== $saveTo) {
[861] Fix | Delete
if (is_resource($saveTo)) {
[862] Fix | Delete
$rest->fp = $saveTo;
[863] Fix | Delete
if (!is_bool($resume)) $rest->setHeader('Range', $resume);
[864] Fix | Delete
} else {
[865] Fix | Delete
if ($resume && file_exists($saveTo)) {
[866] Fix | Delete
if (false !== ($rest->fp = @fopen($saveTo, 'ab'))) {
[867] Fix | Delete
$rest->setHeader('Range', "bytes=".filesize($saveTo).'-');
[868] Fix | Delete
$rest->file = realpath($saveTo);
[869] Fix | Delete
} else {
[870] Fix | Delete
$rest->response->error = array('code' => 0, 'message' => 'Unable to open save file for writing: '.$saveTo);
[871] Fix | Delete
}
[872] Fix | Delete
} else {
[873] Fix | Delete
if (false !== ($rest->fp = @fopen($saveTo, 'wb')))
[874] Fix | Delete
$rest->file = realpath($saveTo);
[875] Fix | Delete
else
[876] Fix | Delete
$rest->response->error = array('code' => 0, 'message' => 'Unable to open save file for writing: '.$saveTo);
[877] Fix | Delete
}
[878] Fix | Delete
}
[879] Fix | Delete
}
[880] Fix | Delete
if (false === $rest->response->error) $rest->getResponse();
[881] Fix | Delete
[882] Fix | Delete
if (false === $rest->response->error && ( !$resume && 200 != $rest->response->code) || ( $resume && 206 != $rest->response->code && 200 != $rest->response->code))
[883] Fix | Delete
$rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
[884] Fix | Delete
if (false !== $rest->response->error) {
[885] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::getObject({$bucket}, {$uri}): [%s] %s",
[886] Fix | Delete
$rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__);
[887] Fix | Delete
return false;
[888] Fix | Delete
}
[889] Fix | Delete
return $rest->response;
[890] Fix | Delete
}
[891] Fix | Delete
[892] Fix | Delete
[893] Fix | Delete
/**
[894] Fix | Delete
* Get object information
[895] Fix | Delete
*
[896] Fix | Delete
* @param string $bucket Bucket name
[897] Fix | Delete
* @param string $uri Object URI
[898] Fix | Delete
* @param boolean $returnInfo Return response information
[899] Fix | Delete
*
[900] Fix | Delete
* @return mixed | false
[901] Fix | Delete
*/
[902] Fix | Delete
public function getObjectInfo($bucket, $uri, $returnInfo = true) {
[903] Fix | Delete
$rest = new UpdraftPlus_S3Request('HEAD', $bucket, $uri, $this->endpoint, $this->use_dns_bucket_name, $this);
[904] Fix | Delete
$rest = $rest->getResponse();
[905] Fix | Delete
if (false === $rest->error && (200 !== $rest->code && 404 !== $rest->code))
[906] Fix | Delete
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
[907] Fix | Delete
if (false !== $rest->error) {
[908] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::getObjectInfo({$bucket}, {$uri}): [%s] %s",
[909] Fix | Delete
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
[910] Fix | Delete
return false;
[911] Fix | Delete
}
[912] Fix | Delete
return (200 == $rest->code) ? ($returnInfo ? $rest->headers : true) : false;
[913] Fix | Delete
}
[914] Fix | Delete
[915] Fix | Delete
/**
[916] Fix | Delete
* Copy an object
[917] Fix | Delete
*
[918] Fix | Delete
* @param string $bucket Source bucket name
[919] Fix | Delete
* @param string $uri Source object URI
[920] Fix | Delete
* @param string $bucket Destination bucket name
[921] Fix | Delete
* @param string $uri Destination object URI
[922] Fix | Delete
* @param string $acl ACL constant
[923] Fix | Delete
* @param array $metaHeaders Optional array of x-amz-meta-* headers
[924] Fix | Delete
* @param array $requestHeaders Optional array of request headers (content type, disposition, etc.)
[925] Fix | Delete
* @param string $storageClass Storage class constant
[926] Fix | Delete
*
[927] Fix | Delete
* @return mixed | false
[928] Fix | Delete
*/
[929] Fix | Delete
public function copyObject($srcBucket, $srcUri, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array(), $storageClass = self::STORAGE_CLASS_STANDARD) {
[930] Fix | Delete
$rest = new UpdraftPlus_S3Request('PUT', $bucket, $uri, $this->endpoint, $this->use_dns_bucket_name, $this);
[931] Fix | Delete
$rest->setHeader('Content-Length', 0);
[932] Fix | Delete
foreach ($requestHeaders as $h => $v) $rest->setHeader($h, $v);
[933] Fix | Delete
foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v);
[934] Fix | Delete
if (self::STORAGE_CLASS_STANDARD !== $storageClass) // Storage class
[935] Fix | Delete
$rest->setAmzHeader('x-amz-storage-class', $storageClass);
[936] Fix | Delete
$rest->setAmzHeader('x-amz-acl', $acl);
[937] Fix | Delete
$rest->setAmzHeader('x-amz-copy-source', sprintf('/%s/%s', $srcBucket, rawurlencode($srcUri)));
[938] Fix | Delete
if (sizeof($requestHeaders) > 0 || sizeof($metaHeaders) > 0)
[939] Fix | Delete
$rest->setAmzHeader('x-amz-metadata-directive', 'REPLACE');
[940] Fix | Delete
[941] Fix | Delete
$rest = $rest->getResponse();
[942] Fix | Delete
if (false === $rest->error && 200 !== $rest->code) {
[943] Fix | Delete
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
[944] Fix | Delete
}
[945] Fix | Delete
[946] Fix | Delete
if (false !== $rest->error) {
[947] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::copyObject({$srcBucket}, {$srcUri}, {$bucket}, {$uri}): [%s] %s",
[948] Fix | Delete
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
[949] Fix | Delete
return false;
[950] Fix | Delete
}
[951] Fix | Delete
return isset($rest->body->LastModified, $rest->body->ETag) ? array(
[952] Fix | Delete
'time' => strtotime((string)$rest->body->LastModified),
[953] Fix | Delete
'hash' => substr((string)$rest->body->ETag, 1, -1)
[954] Fix | Delete
) : false;
[955] Fix | Delete
}
[956] Fix | Delete
[957] Fix | Delete
[958] Fix | Delete
/**
[959] Fix | Delete
* Set logging for a bucket
[960] Fix | Delete
*
[961] Fix | Delete
* @param string $bucket Bucket name
[962] Fix | Delete
* @param string $targetBucket Target bucket (where logs are stored)
[963] Fix | Delete
* @param string $targetPrefix Log prefix (e,g; domain.com-)
[964] Fix | Delete
*
[965] Fix | Delete
* @return boolean
[966] Fix | Delete
*/
[967] Fix | Delete
public function setBucketLogging($bucket, $targetBucket, $targetPrefix = null) {
[968] Fix | Delete
// The S3 log delivery group has to be added to the target bucket's ACP
[969] Fix | Delete
if (null !== $targetBucket && false !== ($acp = $this->getAccessControlPolicy($targetBucket, ''))) {
[970] Fix | Delete
// Only add permissions to the target bucket when they do not exist
[971] Fix | Delete
$aclWriteSet = false;
[972] Fix | Delete
$aclReadSet = false;
[973] Fix | Delete
foreach ($acp['acl'] as $acl)
[974] Fix | Delete
if ('Group' == $acl['type'] && 'http://acs.amazonaws.com/groups/s3/LogDelivery' == $acl['uri']) {
[975] Fix | Delete
if ($acl['permission'] == 'WRITE') $aclWriteSet = true;
[976] Fix | Delete
elseif ($acl['permission'] == 'READ_ACP') $aclReadSet = true;
[977] Fix | Delete
}
[978] Fix | Delete
if (!$aclWriteSet) $acp['acl'][] = array(
[979] Fix | Delete
'type' => 'Group', 'uri' => 'http://acs.amazonaws.com/groups/s3/LogDelivery', 'permission' => 'WRITE'
[980] Fix | Delete
);
[981] Fix | Delete
if (!$aclReadSet) $acp['acl'][] = array(
[982] Fix | Delete
'type' => 'Group', 'uri' => 'http://acs.amazonaws.com/groups/s3/LogDelivery', 'permission' => 'READ_ACP'
[983] Fix | Delete
);
[984] Fix | Delete
if (!$aclReadSet || !$aclWriteSet) $this->setAccessControlPolicy($targetBucket, '', $acp);
[985] Fix | Delete
}
[986] Fix | Delete
[987] Fix | Delete
$dom = new DOMDocument;
[988] Fix | Delete
$bucketLoggingStatus = $dom->createElement('BucketLoggingStatus');
[989] Fix | Delete
$bucketLoggingStatus->setAttribute('xmlns', 'http://s3.amazonaws.com/doc/2006-03-01/');
[990] Fix | Delete
if (null !== $targetBucket) {
[991] Fix | Delete
if (null == $targetPrefix) $targetPrefix = $bucket . '-';
[992] Fix | Delete
$loggingEnabled = $dom->createElement('LoggingEnabled');
[993] Fix | Delete
$loggingEnabled->appendChild($dom->createElement('TargetBucket', $targetBucket));
[994] Fix | Delete
$loggingEnabled->appendChild($dom->createElement('TargetPrefix', $targetPrefix));
[995] Fix | Delete
// TODO: Add TargetGrants?
[996] Fix | Delete
$bucketLoggingStatus->appendChild($loggingEnabled);
[997] Fix | Delete
}
[998] Fix | Delete
$dom->appendChild($bucketLoggingStatus);
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function