aboutsummaryrefslogtreecommitdiffstats
path: root/include/api.php
diff options
context:
space:
mode:
authorHaakon Meland Eriksen <haakon.eriksen@far.no>2015-11-05 16:54:39 +0100
committerHaakon Meland Eriksen <haakon.eriksen@far.no>2015-11-05 16:54:39 +0100
commit91f751d10531e73078f7efb4efa1f5e215a8f871 (patch)
treebbe0b1b7fdd1c2c69a6ed2e001decc735111bc50 /include/api.php
parent07bd396837426fbe4cf3ecd189513d50a14081a1 (diff)
parent0db5a8673d57088ab394cdaf372fb81dbd78bcbb (diff)
downloadvolse-hubzilla-91f751d10531e73078f7efb4efa1f5e215a8f871.tar.gz
volse-hubzilla-91f751d10531e73078f7efb4efa1f5e215a8f871.tar.bz2
volse-hubzilla-91f751d10531e73078f7efb4efa1f5e215a8f871.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'include/api.php')
-rw-r--r--include/api.php26
1 files changed, 15 insertions, 11 deletions
diff --git a/include/api.php b/include/api.php
index 3862ba7eb..b51bcc5f0 100644
--- a/include/api.php
+++ b/include/api.php
@@ -660,26 +660,30 @@ require_once('include/attach.php');
dbesc($_REQUEST['file_id'])
);
if($r) {
- if($r[0]['is_dir'])
- $r[0]['data'] = '';
+ $ptr = $r[0];
+ if($length === 0)
+ $length = intval($ptr['filesize']);
+
+ if($ptr['is_dir'])
+ $ptr['data'] = '';
elseif(! intval($r[0]['os_storage'])) {
- $r[0]['start'] = $start;
- $x = substr(dbunescbin($r[0]['data'],$start,$length));
- $r[0]['length'] = strlen($x);
- $r[0]['data'] = base64_encode($x);
+ $ptr['start'] = $start;
+ $x = substr(dbunescbin($ptr['data'],$start,$length));
+ $ptr['length'] = strlen($x);
+ $ptr['data'] = base64_encode($x);
}
else {
- $fp = fopen(dbunescbin($r[0]['data'],'r'));
+ $fp = fopen(dbunescbin($ptr['data']),'r');
if($fp) {
$seek = fseek($fp,$start,SEEK_SET);
$x = fread($fp,$length);
- $r[0]['start'] = $start;
- $r[0]['length'] = strlen($x);
- $r[0]['data'] = base64_encode($x);
+ $ptr['start'] = $start;
+ $ptr['length'] = strlen($x);
+ $ptr['data'] = base64_encode($x);
}
}
- $ret = array('attach' => $r[0]);
+ $ret = array('attach' => $ptr);
json_return_and_die($ret);
}
killme();