diff --git a/apps/gallery/lib/hooks_handlers.php b/apps/gallery/lib/hooks_handlers.php
index 3c101b1f8a1c07f83c3628c8fb49682cb5fa9ad4..480e41a8bf9a8c714002d3030c2eb14233c52e7e 100644
--- a/apps/gallery/lib/hooks_handlers.php
+++ b/apps/gallery/lib/hooks_handlers.php
@@ -68,7 +68,7 @@ class OC_Gallery_Hooks_Handlers {
 
     if (!self::isPhoto($fullpath)) return;
 
-    $path = substr($fullpath, 0, strrpos($fullpath, '/'));
+    $path = dirname($fullpath);
     if (!self::pathInRoot($path)) return;
     OC_Gallery_Scanner::scanDir($path, $albums);