summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-06-27 18:23:36 (GMT)
committerAleksander Machniak <alec@alec.pl>2013-06-27 18:23:36 (GMT)
commit8b51aa770a9d5637d6f77d42b61841852793061c (patch)
tree12a898e4b0dd6823d31fbd7c8bbb58dc54791d01
parente7175e0413f08339294478c9656594dc86530b21 (diff)
downloadiRony-8b51aa770a9d5637d6f77d42b61841852793061c.tar.gz
Pass file data as file handle to the file backend, using php://temp instead of a real file
-rw-r--r--lib/Kolab/DAV/Node.php36
1 files changed, 27 insertions, 9 deletions
diff --git a/lib/Kolab/DAV/Node.php b/lib/Kolab/DAV/Node.php
index e12b7b5..72bd6bc 100644
--- a/lib/Kolab/DAV/Node.php
+++ b/lib/Kolab/DAV/Node.php
@@ -163,18 +163,36 @@ class Node implements \Sabre\DAV\INode
*/
protected function fileData($name, $data = null)
{
- $rcube = rcube::get_instance();
- $temp_dir = unslashify($rcube->config->get('temp_dir'));
- $file_path = tempnam($temp_dir, 'davFile');
+ if ($this->data && $this->data['type']) {
+ $type = $this->data['type'];
+ }
+ else {
+ $type = 'application/octet-stream';
+ }
- // @TODO: support $data as a resource in the backend
- // @TODO: support $data as string in the backend
- file_put_contents($file_path, $data);
+ // $data can be a resource or a string
+ if (is_resource($data)) {
+ // $data can be php://input or php://temp
+ // php://input is not seekable, we need to "convert"
+ // it to seekable resource, fstat/rewind later will work
+ $meta = stream_get_meta_data($data);
+ if (!$meta['seekable']) {
+ $new_data = fopen('php://temp','r+');
+ stream_copy_to_stream($data, $new_data);
+ rewind($new_data);
+ $data = $new_data;
+ }
+
+ $content = stream_get_contents($data, 1024000, 0);
+ rewind($data);
+ }
+ else {
+ $content = &$data;
+ }
$filedata = array(
- 'path' => $file_path,
- 'size' => filesize($file_path),
- 'type' => rcube_mime::file_content_type($file_path, $name),
+ 'content' => $data,
+ 'type' => rcube_mime::file_content_type($content, $name, $type, true),
);
return $filedata;