images dirs from config
This commit is contained in:
parent
1a4e7dc049
commit
333229d642
2 changed files with 13 additions and 10 deletions
|
@ -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)){
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue