summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-10-21 09:00:57 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2014-10-21 09:00:57 (GMT)
commitcabcf77f6e89b16a33c014ca9f3d4122f089e4c2 (patch)
tree855321bce54c708a1674a465fafcb1247b7a2475
parent2564dbfe54d2bb637fd8b6766d7d8f87557bb1eb (diff)
downloadkolab-chwala-cabcf77f6e89b16a33c014ca9f3d4122f089e4c2.tar.gz
Fix file_create/file_update action via file_api_lib
-rw-r--r--lib/api/file_create.php20
-rw-r--r--lib/file_api_lib.php11
2 files changed, 26 insertions, 5 deletions
diff --git a/lib/api/file_create.php b/lib/api/file_create.php
index fb7de85..5b163a7 100644
--- a/lib/api/file_create.php
+++ b/lib/api/file_create.php
@@ -36,14 +36,28 @@ class file_api_file_create extends file_api_common
}
if (!isset($this->args['content'])) {
- throw new Exception("Missing file content", file_api_core::ERROR_CODE);
+ if (!($this->api instanceof file_api_lib) || empty($this->args['path'])) {
+ throw new Exception("Missing file content", file_api_core::ERROR_CODE);
+ }
+ }
+
+ if (is_resource($this->args['content'])) {
+ $chunk = stream_get_contents($this->args['content'], 1024000, 0);
+ }
+ else if ($this->args['path']) {
+ $chunk = $this->args['path'];
+ $is_file = true;
+ }
+ else {
+ $chunk = $this->args['content'];
}
$request = $this instanceof file_api_file_update ? 'file_update' : 'file_create';
$file = array(
'content' => $this->args['content'],
- 'type' => rcube_mime::file_content_type($this->args['content'],
- $this->args['file'], $this->args['content-type'], true),
+ 'path' => $this->args['path'],
+ 'type' => rcube_mime::file_content_type($chunk,
+ $this->args['file'], $this->args['content-type'], !$is_file),
);
list($driver, $path) = $this->api->get_driver($this->args['file']);
diff --git a/lib/file_api_lib.php b/lib/file_api_lib.php
index 18742c9..c26d320 100644
--- a/lib/file_api_lib.php
+++ b/lib/file_api_lib.php
@@ -54,11 +54,18 @@ class file_api_lib extends file_api_core
case 'file_create':
case 'file_update':
+ $args = array(
+ 'file' => $arguments[0],
+ 'path' => $arguments[1]['path'],
+ 'content' => $arguments[1]['content'],
+ 'content-type' => $arguments[1]['type'],
+ );
+ break;
+
case 'file_delete':
case 'file_info':
$args = array(
- 'file' => $arguments[0],
- 'content' => $arguments[1]['content'],
+ 'file' => $arguments[0],
);
break;