workin proto img
This commit is contained in:
parent
6ccee2307e
commit
ceba006772
21
img/img.php
21
img/img.php
@ -4,19 +4,22 @@ namespace SYSTEM\IMG;
|
|||||||
class img {
|
class img {
|
||||||
private static $imgfolders = array(); //only strings! (catname => array(2.path 3.mask))*
|
private static $imgfolders = array(); //only strings! (catname => array(2.path 3.mask))*
|
||||||
|
|
||||||
public static function registerFolder($cat,$path,$mask){
|
public static function registerFolder($path,$cat,$mask){
|
||||||
self::$imgfolders[$cat] = array($path,$mask);}
|
self::$imgfolders[$cat] = array($path,$mask);}
|
||||||
|
|
||||||
public static function get($cat,$id = null,$returnasjson=false){
|
public static function get($cat,$id = null,$returnasjson = false){
|
||||||
$result = null;
|
if(!array_key_exists($cat, self::$imgfolders)){
|
||||||
if(array_key_exists($cat, self::$imgfolders)){
|
throw new \SYSTEM\LOG\ERROR("No matching Cat '".$cat."' found.");}
|
||||||
|
|
||||||
$folder = self::getFolder(self::$imgfolders[$cat][0],self::$imgfolders[$cat][1]);
|
$folder = self::getFolder(self::$imgfolders[$cat][0],self::$imgfolders[$cat][1]);
|
||||||
$result = ($id == null) ? $folder : (array_key_exists($id, $folder)) ? file_get_contents($folder[$id]) : null;}
|
if($id == null){
|
||||||
|
return $returnasjson ? \SYSTEM\LOG\JsonResult::toString($folder) : $folder;}
|
||||||
|
|
||||||
if($returnasjson && $result == null){
|
if(!in_array($id, $folder)){
|
||||||
throw new \SYSTEM\LOG\ERROR("No matching Cat '".$cat."' or Key '".$id."' found or Folder is empty.");}
|
throw new \SYSTEM\LOG\ERROR("No matching ID '".$id."' found.");}
|
||||||
|
|
||||||
return $returnasjson ? \SYSTEM\LOG\JsonResult::toString($result) : $result;
|
\SYSTEM\HEADER::PNG();
|
||||||
|
return file_get_contents(self::$imgfolders[$cat][0].$id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function put($cat,$id,$contents){
|
public static function put($cat,$id,$contents){
|
||||||
@ -25,7 +28,7 @@ class img {
|
|||||||
private static function getFolder($folder,$mask){
|
private static function getFolder($folder,$mask){
|
||||||
$files = array();
|
$files = array();
|
||||||
foreach (glob($folder.$mask) as $file) {
|
foreach (glob($folder.$mask) as $file) {
|
||||||
$files[] = $file;}
|
$files[] = basename($file);}
|
||||||
return $files;
|
return $files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user