Skip to content

Commit

Permalink
Fix for issue transloadit#8: CURL depricated functions (PHP 5.5)
Browse files Browse the repository at this point in the history
Fix for deprecated @filename API in curl by using the supported CURLFile class.
  • Loading branch information
ABerkhout committed Feb 13, 2015
1 parent 2b729de commit bd8a7d7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/transloadit/CurlRequest.php
Expand Up @@ -45,7 +45,19 @@ public function getCurlOptions() {
if (is_int($field)) {
$field = 'file_'.($field+1);
}
$fields[$field] = '@'.$file;

// -- Start edit --
// Edit by Aart Berkhout involving issue #8: CURL depricated functions (PHP 5.5)
// https://github.com/transloadit/php-sdk/issues/8
if (function_exists('curl_file_create')) {
// For >= PHP 5.5 use curl_file_create
$fields[$field] = curl_file_create($file);
}else{
// For < PHP 5.5 use @filename API
$fields[$field] = '@'.$file;
}
// -- End edit --

}
$options[CURLOPT_POSTFIELDS] = $fields;
}
Expand All @@ -55,6 +67,11 @@ public function getCurlOptions() {

public function execute($response = null) {
$curl = curl_init();

// -- Start edit --
// For PHP 5.6 Safe Upload is required to upload files using curl in PHP 5.5, add the CURLOPT_SAFE_UPLOAD = true option
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, function_exists('curl_file_create') ? true : false);
// -- End edit --

curl_setopt_array($curl, $this->getCurlOptions());

Expand Down

0 comments on commit bd8a7d7

Please sign in to comment.