diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php
index 4b015e4d1f58ea96bd02ff272b96c16b8d397171..733ed95974fed99bd79e2def45871baf64ca9202 100644
--- a/apps/files/ajax/upload.php
+++ b/apps/files/ajax/upload.php
@@ -34,9 +34,10 @@ if (empty($_POST['dirToken'])) {
 		}
 
 		// The token defines the target directory (security reasons)
+		$sharedItem = array_pop($sharedItem);
 		$dir = sprintf(
 			"/%s/%s",
-			array_pop($sharedItem)['path'],
+			$sharedItem['path'],
 			isset($_POST['subdir']) ? $_POST['subdir'] : ''
 		);