aboutsummaryrefslogtreecommitdiffstats
path: root/include/attach.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2020-12-21 21:37:10 +0000
committerMario <mario@mariovavti.com>2020-12-21 21:37:10 +0000
commitd118ab71e6aa4f300ba6e42663d13a63a2323122 (patch)
tree08282fa1dfb0a2f975fd9d338df7677fa84ea5e9 /include/attach.php
parent81a1aedeb9a4e07c3d1e11905ad3e2434d635e86 (diff)
downloadvolse-hubzilla-d118ab71e6aa4f300ba6e42663d13a63a2323122.tar.gz
volse-hubzilla-d118ab71e6aa4f300ba6e42663d13a63a2323122.tar.bz2
volse-hubzilla-d118ab71e6aa4f300ba6e42663d13a63a2323122.zip
files_ng: implement directory and bulk file download
Diffstat (limited to 'include/attach.php')
-rw-r--r--include/attach.php39
1 files changed, 38 insertions, 1 deletions
diff --git a/include/attach.php b/include/attach.php
index 8ebe2d243..b4f697f81 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -300,6 +300,44 @@ function attach_by_hash($hash, $observer_hash, $rev = 0) {
}
+/**
+ * @brief Find an attachment by id.
+ *
+ * Returns the entire attach structure including data.
+ *
+ * This could exhaust memory so most useful only when immediately sending the data.
+ *
+ * @param string $hash
+ * @param string $observer_hash
+ * @return array
+ */
+function attach_by_id($id, $observer_hash) {
+
+ $ret = array('success' => false);
+
+ // Check for existence, which will also provide us the owner uid
+
+ $r = q("SELECT * FROM attach WHERE id = %d",
+ intval($id)
+ );
+ if(! $r) {
+ $ret['message'] = t('Item was not found.');
+ return $ret;
+ }
+
+ if(! attach_can_view($r[0]['uid'], $observer_hash, $r[0]['hash'])) {
+ $ret['message'] = t('Permission denied.');
+ return $ret;
+ }
+
+ $r[0]['content'] = dbunescbin($r[0]['content']);
+
+ $ret['success'] = true;
+ $ret['data'] = $r[0];
+
+ return $ret;
+}
+
function attach_can_view($uid,$ob_hash,$resource) {
$sql_extra = permissions_sql($uid,$ob_hash);
@@ -1120,7 +1158,6 @@ function attach_mkdir($channel, $observer_hash, $arr = null) {
if(! is_dir($os_basepath))
os_mkdir($os_basepath,STORAGE_DEFAULT_PERMISSIONS, true);
-
$os_basepath .= '/';
if(! perm_is_allowed($channel_id, $observer_hash, 'write_storage')) {