Commit dd0f4683 authored by Keven's avatar Keven
Browse files

Fix upload for PHP >= 5.5

parent ae35afed
......@@ -15,6 +15,7 @@
"autoload": {
"psr-0": {
"Libcast": "src"
}
},
"files": ["src/functions.php"]
}
}
......@@ -64,7 +64,7 @@ class SendFile extends FileCommand
if (is_readable($path)) { // Local file
$this->fileSize = filesize($path);
$fields = array('path' => "@$path", 'name' => $name);
$fields = array('path' => curl_file_create($path), 'name' => $name);
if (!is_null($slug)) {
$fields['folder'] = $slug;
}
......@@ -118,7 +118,7 @@ class SendFile extends FileCommand
$chunk = 0;
foreach ($chunks as $chunkPath) {
$this->requestOptions[CURLOPT_POSTFIELDS]['chunk'] = $chunk++;
$this->requestOptions[CURLOPT_POSTFIELDS]['path'] = "@$chunkPath";
$this->requestOptions[CURLOPT_POSTFIELDS]['path'] = curl_file_create($chunkPath);
$response = $this->send($client);
unlink($chunkPath);
}
......@@ -137,6 +137,11 @@ class SendFile extends FileCommand
*/
private function splitFile($path, $chunkSize)
{
// PHP >= 5.5
if ($path instanceof \CURLFile) {
$path = $path->name;
}
if ('@' === $path{0}) {
$path = substr($path, 1);
}
......
<?php
/**
*
* @see php.net/curl_file_create
*/
if (!function_exists('curl_file_create')) {
if (!extension_loaded('curl')) {
throw new \Exception('cURL extension is required by the Libcast API client.');
}
// We are in PHP < 5.5
/**
*
* @param string $filename
* @param string $mimetype
* @param string $postname
*
* @return string
*/
function curl_file_create($filename, $mimetype = '', $postname = '')
{
return "@$filename;filename="
. ($postname ?: basename($filename))
. ($mimetype ? ";type=$mimetype" : '');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment