From ea0988065184a3a971743254c4f0d83f872b8c00 Mon Sep 17 00:00:00 2001 From: Joel Margolis Date: Sun, 16 Aug 2015 12:42:14 -0400 Subject: [PATCH] uploading/sending changes. mime now based on data --- src/snapchat.php | 51 ++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/snapchat.php b/src/snapchat.php index 4dd9b13..aa7ae40 100644 --- a/src/snapchat.php +++ b/src/snapchat.php @@ -2017,7 +2017,7 @@ public function updateUser($acceptSnapCashV2Tos = true, $acceptSnapCashTos = tru * @return mixed * The ID of the uploaded media or FALSE on failure. */ - public function upload($data, $media) + public function upload($data) { // Make sure we're logged in and have a valid access token. if(!$this->auth_token || !$this->username) @@ -2026,7 +2026,7 @@ public function upload($data, $media) } $finfo = finfo_open(FILEINFO_MIME_TYPE); - $mime = finfo_file($finfo, $media); + $mime = finfo_buffer($finfo, $data); if(strstr($mime, "video/")) { @@ -2038,6 +2038,7 @@ public function upload($data, $media) } else { + echo "\nBad file type, must be a photo or video.\n"; return false; } @@ -2159,29 +2160,33 @@ public function send($media, $recipients, $text = null, $time = 3) $mediaData = file_get_contents($media); } - $media_id = $this->upload($mediaData, $media); + $media_id = $this->upload($mediaData); - $timestamp = parent::timestamp(); - $result = parent::post( - '/loq/send', - array( - 'media_id' => $media_id, - 'zipped' => '0', - 'recipients' => $recipients, - 'username' => $this->username, - 'time' => $time, - 'timestamp' => $timestamp, - 'features_map' => '{}' - ), - array( - $this->auth_token, - $timestamp - ), - $multipart = false, - $debug = $this->debug - ); + if($media_id) + { + $timestamp = parent::timestamp(); + $result = parent::post( + '/loq/send', + array( + 'media_id' => $media_id, + 'zipped' => '0', + 'recipients' => $recipients, + 'username' => $this->username, + 'time' => $time, + 'timestamp' => $timestamp, + 'features_map' => '{}' + ), + array( + $this->auth_token, + $timestamp + ), + $multipart = false, + $debug = $this->debug + ); + return $result; + } - return $result; + return $media_id; } /**