diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index d981fcf..1cae6ea --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,9 @@ custom.ini -# Ignore images content +# Ignore images & thumbnails directories (legacy) i/* -!i/.gitkeep - -# Ignore thumbnails content t/* -!t/.gitkeep -# Ignore all files in data but keep folder itself (and logs subfolder) +# Ignore all files in data but keep directory itself data/* !data/.gitkeep -!data/logs/ - -# Ignore all logs files but keep folder itself -data/logs/* -!data/logs/.gitkeep diff --git a/app/image.class.php b/app/image.class.php index 6d9947e..52bca48 100755 --- a/app/image.class.php +++ b/app/image.class.php @@ -3,9 +3,6 @@ defined('PROJECT_PATH') OR exit('No direct script access allowed'); class Image { - const IMAGES = 'i/'; - const THUMBS = 't/'; - const THUMB_W = 476; const THUMB_H = 476; @@ -126,6 +123,13 @@ class Image return $d; } + // Ensure, that directories exists + $_images_path = Config::get('images_path'); + $_thumbnails_path = Config::get('thumbnails_path'); + if((!is_dir($_images_path) && !mkdir($_images_path, 755, true)) || (!is_dir($_thumbnails_path) && !mkdir($_thumbnails_path, 755, true))){ + throw new Exception("Images or thumbnails directory could not be created."); + } + // Get metadata $name = $_FILES['file']['name']; $ext = pathinfo($name, PATHINFO_EXTENSION); @@ -138,15 +142,10 @@ class Image $name, $ext, $md5 )->last_id(); - // Ensure, that directories exists - if((!is_dir(self::IMAGES) && !mkdir(self::IMAGES)) || (!is_dir(self::THUMBS) && !mkdir(self::THUMBS))){ - throw new Exception("Images / thumbnails directories could not be created."); - } - // Create path name $name = dechex($id).self::random_str(3).".".$ext; - $path = self::IMAGES.$name; - $thumb = self::THUMBS.$name; + $path = $_images_path.$name; + $thumb = $_thumbnails_path.$name; // Save path if(!move_uploaded_file($_FILES['file']['tmp_name'], $path)){ diff --git a/app/log.class.php b/app/log.class.php index 626e624..b6ea52a 100755 --- a/app/log.class.php +++ b/app/log.class.php @@ -3,8 +3,6 @@ defined('PROJECT_PATH') OR exit('No direct script access allowed'); class Log { - const PATH = 'data/logs/'; - private static $_files = [ "ajax_access", "ajax_errors", @@ -17,7 +15,12 @@ class Log return ; } - if(false === file_put_contents(PROJECT_PATH.static::PATH.$_file.".log", self::line($_text), FILE_APPEND) && Config::get_safe('debug', false)){ + $_logs_path = Config::get('logs_path'); + if(!is_dir($_logs_path) && !mkdir($_logs_path, 755, true)){ + die("Logs directory could not be created."); + } + + if(false === file_put_contents($_logs_path.$_file.".log", self::line($_text), FILE_APPEND) && Config::get_safe('debug', false)){ die(sprintf("Can't write to %s.log file.", $_file)); } } diff --git a/config.ini b/config.ini index 03bbcbe..9da898a 100755 --- a/config.ini +++ b/config.ini @@ -37,6 +37,11 @@ pass = demo ;visitor[user] = pass ;visitor[user] = pass +[directories] +images_path = data/i/ +thumbnails_path = data/t/ +logs_path = data/logs/ + [system] system_name = blog version = 1.18 diff --git a/i/.gitkeep b/i/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/t/.gitkeep b/t/.gitkeep deleted file mode 100644 index e69de29..0000000