Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dailymotion/dailymotion-sdk-php
Browse files Browse the repository at this point in the history
* 'master' of github.com:dailymotion/dailymotion-sdk-php:
  Typo bugfix
  Added a CurlFile object that deprecates the old @filename syntax for PHP 5.5

Conflicts:
	Dailymotion.php
  • Loading branch information
Nicolas Grevet committed Sep 11, 2014
2 parents be81a04 + 8c3cef0 commit 95e157e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion Dailymotion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Here is a usage example:
<?php

$api = new Dailymotion();
$api->setGrantType(Dailymotion::GRANT_TYPE_AUTHORIZATION, $apiKey, $apiSecret)
$api->setGrantType(Dailymotion::GRANT_TYPE_AUTHORIZATION, $apiKey, $apiSecret);

try
{
Expand Down

0 comments on commit 95e157e

Please sign in to comment.