From 88c6b54b52504f335d36e631bf7ed0aa09f228e5 Mon Sep 17 00:00:00 2001 From: andynazay153 Date: Tue, 12 Jun 2018 19:46:33 -0700 Subject: [PATCH] Allow for upload/download from/to memory Useful if files are accessed rarely and should not be saved to avoid I/O bottleneck --- spaces.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/spaces.php b/spaces.php index 806c2a9..9cd6a76 100644 --- a/spaces.php +++ b/spaces.php @@ -258,11 +258,16 @@ class SpacesConnect { if($access == "public") { $access = "public-read"; } + if(!is_file($pathToFile)){ + $file = $pathToFile; + }else{ + $file = fopen($pathToFile, 'r+'); + } try { $result = $this->client->putObject(array( 'Bucket' => $this->space, 'Key' => $save_as, - 'Body' => fopen($pathToFile, 'r+'), + 'Body' => $file, "ACL" => $access )); @@ -281,13 +286,17 @@ class SpacesConnect { /* Download a file. */ - function DownloadFile($fileName, $destinationPath) { + function DownloadFile($fileName, $destinationPath = false) { try { $result = $this->client->getObject(array( 'Bucket' => $this->space, 'Key' => $fileName, 'SaveAs' => $destinationPath )); + + if(!$destinationPath) { + return $result; + } return $this->ObjReturn($result->toArray()); }