From f1250a3867f482fd5bae6f16e3fb779c7323f947 Mon Sep 17 00:00:00 2001 From: Bartek Przybylski <bart.p.pl@gmail.com> Date: Sat, 9 Jun 2012 15:26:26 +0200 Subject: [PATCH] add function in filesystem to strip webroot --- lib/filesystem.php | 14 ++++++++++++++ lib/image.php | 7 +------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/filesystem.php b/lib/filesystem.php index cac7e8648e..198f00873c 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -341,6 +341,20 @@ class OC_Filesystem{ return self::$defaultInstance->getLocalFile($path); } + /** + * return path to file which reflects one visible in browser + * @param string path + * @return string + */ + static public function getLocalPath($path) { + $datadir = \OCP\Config::getSystemValue('datadirectory').'/'.\OC_User::getUser().'/files'; + $newpath = $path; + if (strncmp($newpath, $datadir, strlen($datadir)) == 0) { + $newpath = substr($path, strlen($datadir)); + } + return $newpath; + } + /** * check if the requested path is valid * @param string path diff --git a/lib/image.php b/lib/image.php index 77efc56d8c..f119c99633 100644 --- a/lib/image.php +++ b/lib/image.php @@ -402,12 +402,7 @@ class OC_Image { default: // this is mostly file created from encrypted file - $datadir = \OCP\Config::getSystemValue('datadirectory').'/'.\OC_User::getUser().'/files'; - $newimgpath = $imagepath; - if (strncmp($newimgpath, $datadir, strlen($datadir)) == 0) { - $newimgpath = substr($imagepath, strlen($datadir)); - } - $this->resource = imagecreatefromstring(\OC_Filesystem::file_get_contents($newimgpath)); + $this->resource = imagecreatefromstring(\OC_Filesystem::file_get_contents(\OC_Filesystem::getLocalPath($newimgpath))); $itype = IMAGETYPE_PNG; OC_Log::write('core','OC_Image->loadFromFile, Default', OC_Log::DEBUG); break; -- GitLab