From 333229d64228f142158c83d330edcd190de3996f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 26 Dec 2019 18:05:34 +0100 Subject: [PATCH 1/4] images dirs from config --- app/image.class.php | 19 +++++++++---------- config.ini | 4 ++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/image.class.php b/app/image.class.php index 6d9947e..c61e77a 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)) || (!is_dir($_thumbnails_path) && !mkdir($_thumbnails_path))){ + 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/config.ini b/config.ini index e1e659d..6e0ab80 100755 --- a/config.ini +++ b/config.ini @@ -37,6 +37,10 @@ pass = demo ;visitor[user] = pass ;visitor[user] = pass +[directories] +images_path = i/ +thumbnails_path = t/ + [system] system_name = blog version = 1.18 From d2906509ee063d561b0fdde1b8baa316bb8612c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 26 Dec 2019 18:07:32 +0100 Subject: [PATCH 2/4] image dirs with chmod 755 and recursive --- app/image.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/image.class.php b/app/image.class.php index c61e77a..52bca48 100755 --- a/app/image.class.php +++ b/app/image.class.php @@ -126,7 +126,7 @@ class Image // Ensure, that directories exists $_images_path = Config::get('images_path'); $_thumbnails_path = Config::get('thumbnails_path'); - if((!is_dir($_images_path) && !mkdir($_images_path)) || (!is_dir($_thumbnails_path) && !mkdir($_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."); } From cda2cf8f3c7fda9dd436dc4685bdb12add3abf69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 26 Dec 2019 18:18:26 +0100 Subject: [PATCH 3/4] logs dir in config & mkdir if not exist --- app/log.class.php | 9 ++++++--- config.ini | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) 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 6e0ab80..fc1e3da 100755 --- a/config.ini +++ b/config.ini @@ -40,6 +40,7 @@ pass = demo [directories] images_path = i/ thumbnails_path = t/ +logs_path = data/logs/ [system] system_name = blog From 945bf34185b664c6456ae09ce16e65332f75e168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 26 Dec 2019 18:20:19 +0100 Subject: [PATCH 4/4] images dir changed --- .gitignore | 13 ++----------- config.ini | 4 ++-- i/.gitkeep | 0 t/.gitkeep | 0 4 files changed, 4 insertions(+), 13 deletions(-) mode change 100644 => 100755 .gitignore delete mode 100644 i/.gitkeep delete mode 100644 t/.gitkeep 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/config.ini b/config.ini index fc1e3da..db776ec 100755 --- a/config.ini +++ b/config.ini @@ -38,8 +38,8 @@ pass = demo ;visitor[user] = pass [directories] -images_path = i/ -thumbnails_path = t/ +images_path = data/i/ +thumbnails_path = data/t/ logs_path = data/logs/ [system] 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