From 6e8d9721a081abd416270b66f7c599142129351c Mon Sep 17 00:00:00 2001 From: icewing Date: Wed, 30 Apr 2008 10:34:39 +0000 Subject: Marcus Povey * git-svn-id: https://code.elgg.org/elgg/trunk@572 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/filestore.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'engine/lib') diff --git a/engine/lib/filestore.php b/engine/lib/filestore.php index fb37fee57..5a4a60b8b 100644 --- a/engine/lib/filestore.php +++ b/engine/lib/filestore.php @@ -122,11 +122,27 @@ public function open(ElggFile $file, $mode) { - $name = $file->getFilename(); - $matrix = $this->make_file_matrix($name); + // Full path and filename + $fullname = $file->getFilename(); + + // Split into path and name + $ls = strrpos($fullname,"/"); + if ($ls===false) $ls = 0; + + $path = substr($fullname, 0, $ls); + $name = substr($fullname, $ls); + + // Construct matrix out of user + $owner = $file->getOwnerEntity(); + if (!$owner) + $owner = $_SESSION['user']; + + if ((!$owner) || (!$owner->username)) throw InvalidParameterException("All files must have an owner!"); + + $matrix = $this->make_file_matrix($owner->username); // Try and create the directory - try { $this->make_directory_root($this->dir_root . $matrix); } catch (Exception $e){} + try { $this->make_directory_root($this->dir_root . $matrix . $path); } catch (Exception $e){} switch ($mode) { @@ -136,7 +152,7 @@ default: throw new InvalidParameterException("Unrecognised file mode '$mode'"); } - return fopen($this->dir_root . $matrix . $name, $mode); + return fopen($this->dir_root . $matrix . $fullname, $mode); } public function write($f, $data) -- cgit v1.2.3