Commit bc6ea0ad authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge pull request #254 from Livich/develop

Fixes issue with file uploading
parents f92f78e5 52232601
......@@ -171,15 +171,35 @@ class Request
{
$debug_handle = TelegramLog::getDebugLogTempStream();
try {
//Fix so that the keyboard markup is a string, not an object
if (isset($data['reply_markup']) && !is_string($data['reply_markup'])) {
$data['reply_markup'] = (string)$data['reply_markup'];
//Fix so that the keyboard markup is a string, not an object
if (isset($data['reply_markup']) && !is_string($data['reply_markup'])) {
$data['reply_markup'] = (string)$data['reply_markup'];
}
$request_params = ['debug' => $debug_handle];
//Check for resources in data
$contains_resource = false;
foreach ($data as $item) {
if (is_resource($item)) {
$contains_resource = true;
break;
}
}
//Reformat data array in multipart way
if ($contains_resource) {
foreach ($data as $key => $item) {
$request_params['multipart'][] = array('name' => $key, 'contents' => $item);
}
} else {
$request_params['form_params'] = $data;
}
try {
$response = self::$client->post(
'/bot' . self::$telegram->getApiKey() . '/' . $action,
['debug' => $debug_handle, 'form_params' => $data]
$request_params
);
} catch (RequestException $e) {
throw new TelegramException($e->getMessage());
......@@ -239,11 +259,15 @@ class Request
*
* @param string $file
*
* @return \CURLFile
* @return resource
*/
protected static function encodeFile($file)
{
return new \CURLFile($file);
$fp = fopen($file, 'r');
if ($fp === false) {
throw new TelegramException('Cannot open ' . $file . ' for reading');
}
return $fp;
}
/**
......
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