diff --git a/examples/FileSharing.php b/examples/FileSharing.php index f980092d..b855bbd4 100644 --- a/examples/FileSharing.php +++ b/examples/FileSharing.php @@ -16,20 +16,21 @@ $pubnub = new PubNub($config); // Sending file -// $fileHandle = fopen(__DIR__ . DIRECTORY_SEPARATOR . $fileName, "r"); -// $sendFileResult = $pubnub->sendFile() -// ->channel($channelName) -// ->fileName($fileName) -// ->message("Hello from PHP SDK") -// ->fileHandle($fileHandle) -// ->sync(); +$fileHandle = fopen(__DIR__ . DIRECTORY_SEPARATOR . $fileName, "r"); +$sendFileResult = $pubnub->sendFile() + ->channel($channelName) + ->fileName($fileName) + ->message("Hello from PHP SDK") + ->fileHandle($fileHandle) + ->sync(); -// fclose($fileHandle); +fclose($fileHandle); // Listing files in the channel $channelFiles = $pubnub->listFiles()->channel($channelName)->sync(); -if ($channelFiles->getCount() > 0) { - print("There are {$channelFiles->getCount()} files in the channel {$channelName}\n"); +$fileCount = $channelFiles->getCount(); +if ($fileCount > 0) { + print("There are {$fileCount} files in the channel {$channelName}\n"); foreach ($channelFiles->getFiles() as $idx => $file) { print("File[{$idx}]: {$file->getName()} with ID: {$file->getId()}," . "size {$file->getSize()}, created at: {$file->getCreationTime()}\n"); diff --git a/src/PubNub/Endpoints/FileSharing/PublishFileMessage.php b/src/PubNub/Endpoints/FileSharing/PublishFileMessage.php index abc9f806..c9129809 100644 --- a/src/PubNub/Endpoints/FileSharing/PublishFileMessage.php +++ b/src/PubNub/Endpoints/FileSharing/PublishFileMessage.php @@ -56,16 +56,16 @@ protected function buildPath() public function encryptMessage($message) { $crypto = $this->pubnub->getCryptoSafe(); - $message = PubNubUtil::writeValueAsString($message); + $messageString = PubNubUtil::writeValueAsString($message); if ($crypto) { - return $crypto->encrypt($message); + return $crypto->encrypt($messageString); } - return $message; + return $messageString; } protected function buildMessage() { - $message = [ + $messageData = [ "message" => $this->message, "file" => [ "id" => $this->fileId, @@ -73,7 +73,7 @@ protected function buildMessage() ] ]; - return $this->encryptMessage($message); + return $this->encryptMessage($messageData); } protected function customParams() diff --git a/src/PubNub/Endpoints/FileSharing/SendFile.php b/src/PubNub/Endpoints/FileSharing/SendFile.php index 89ea22fc..02ee6b43 100644 --- a/src/PubNub/Endpoints/FileSharing/SendFile.php +++ b/src/PubNub/Endpoints/FileSharing/SendFile.php @@ -266,13 +266,13 @@ public function sync() if (isset($this->meta)) { $publishRequest->meta($this->meta); } - if (isset($this->meta)) { + if (isset($this->message)) { $publishRequest->message($this->message); } - if (isset($this->meta)) { + if (isset($this->shouldStore)) { $publishRequest->shouldStore($this->shouldStore); } - if (isset($this->meta)) { + if (isset($this->ttl)) { $publishRequest->ttl($this->ttl); }