From dbb07961f607ac8a080ade958163c784e645407e Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 4 Oct 2016 10:49:55 +0200 Subject: [PATCH] allow to specify a subdirectory in attach_file as part of $file[name] parameter --- api/src/Link.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/api/src/Link.php b/api/src/Link.php index 1ed09b009f..708fc8477b 100644 --- a/api/src/Link.php +++ b/api/src/Link.php @@ -1166,7 +1166,7 @@ class Link extends Link\Storage * @param string $app appname to linke the file to * @param string $id id in $app * @param array $file informations about the file in format of the etemplate file-type - * $file['name'] name of the file (no directory) + * $file['name'] name of the file (optional incl. a directory) * $file['type'] mine-type of the file * $file['tmp_name'] name of the uploaded file (incl. directory) or resource of opened file * @param string $comment ='' comment to add to the link @@ -1174,7 +1174,16 @@ class Link extends Link\Storage */ static function attach_file($app,$id,$file,$comment='') { - $entry_dir = self::vfs_path($app,$id); + // check if $file['name'] specifies a subdirectory, in which case use and, if necessary, create it + if (is_array($file) && strpos($file['name'], '/') && strpos($file['name'], '..') === false) + { + $entry_dir = self::vfs_path($app, $id, Vfs::dirname($file['name'])); + $file['name'] = Vfs::basename($file['name']); + } + else + { + $entry_dir = self::vfs_path($app,$id); + } if (self::DEBUG) { echo "

attach_file: app='$app', id='$id', tmp_name='$file[tmp_name]', name='$file[name]', size='$file[size]', type='$file[type]', path='$file[path]', ip='$file[ip]', comment='$comment', entry_dir='$entry_dir'

\n";