From ea0cd6c91984d65d9378d51f3bf1d1e4fad36484 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Wed, 21 Nov 2018 16:36:11 +0100 Subject: [PATCH] Filesystem storage: add "index.html" files in dirs --- src/Model/Storage/Filesystem.php | 40 +++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/Model/Storage/Filesystem.php b/src/Model/Storage/Filesystem.php index de3e88be08..07af0f1357 100644 --- a/src/Model/Storage/Filesystem.php +++ b/src/Model/Storage/Filesystem.php @@ -46,6 +46,36 @@ class Filesystem implements IStorage return "{$base}/{$fold1}/{$fold2}/{$file}"; } + + /** + * @brief Create dirctory tree to store file, with .htaccess and index.html files + * @param string $file Path and filename + */ + private static function createFoldersForFile($file) + { + $path = dirname($file); + + if (!is_dir($path)) { + if (!mkdir($path, 0770, true)) { + Logger::log("Failed to create dirs {$path}"); + echo L10n::t("Filesystem storage failed to create '%s'. Check you write permissions.", $path); + killme(); + } + } + + $base = self::getBasePath(); + + while ($path !== $base) { + if (!is_file($path . "/index.html")) { + file_put_contents($path . "/index.html", ""); + } + $path = dirname($path); + } + if (!is_file($path . "/index.html")) { + file_put_contents($path . "/index.html", ""); + } + } + public static function get($ref) { $file = self::pathForRef($ref); @@ -61,17 +91,9 @@ class Filesystem implements IStorage if ($ref === "") { $ref = Strings::getRandomHex(); } - $file = self::pathForRef($ref); - $path = dirname($file); - if (!is_dir($path)) { - if (!mkdir($path, 0770, true)) { - Logger::log("Failed to create dirs {$path}"); - echo L10n::t("Filesystem storage failed to create '%s'. Check you write permissions.", $path); - killme(); - } - } + self::createFoldersForFile($file); $r = file_put_contents($file, $data); if ($r === FALSE) { -- 2.39.5