diff --git a/Dailymotion.php b/Dailymotion.php index 1d5784e..175d92a 100644 --- a/Dailymotion.php +++ b/Dailymotion.php @@ -267,6 +267,26 @@ public function getAuthorizationUrl($display = self::DISPLAY_PAGE) ); } + /** + * Get the file path with the cURL format. + * PHP 5.5 introduced a CurlFile object that deprecates the old `@filename` syntax. + * See: https://wiki.php.net/rfc/curl-file-upload + * + * @param $filePath Path to the file to upload on the local filesystem. + * @return mixed cURL file path. + */ + protected function getCurlFile($filePath) + { + if (function_exists('curl_file_create')) + { + return curl_file_create($filePath); + } + else + { + return sprintf("@%s", $filePath); + } + } + /** * Upload a file on Dailymotion's servers and generate an URL to be used with API methods. * Caution: This does not create a video on Dailymotion, it only uploads a file to Dailymotion's servers for you to @@ -297,7 +317,7 @@ public function uploadFile($filePath, $forceHostname = null) // Upload the file to Dailymotion's servers $result = json_decode( - $this->httpRequest($result['upload_url'], array('file' => "@{$filePath}")), + $this->httpRequest($result['upload_url'], array('file' => $this->getCurlFile($filePath))), true ); $this->timeout = $timeout; diff --git a/README.md b/README.md index c235dbe..54dfd03 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Here is a usage example: setGrantType(Dailymotion::GRANT_TYPE_AUTHORIZATION, $apiKey, $apiSecret) + $api->setGrantType(Dailymotion::GRANT_TYPE_AUTHORIZATION, $apiKey, $apiSecret); try {