workin proto img
This commit is contained in:
parent
6ccee2307e
commit
ceba006772
19
img/img.php
19
img/img.php
@ -4,19 +4,22 @@ namespace SYSTEM\IMG;
|
||||
class img {
|
||||
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);}
|
||||
|
||||
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]);
|
||||
$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){
|
||||
throw new \SYSTEM\LOG\ERROR("No matching Cat '".$cat."' or Key '".$id."' found or Folder is empty.");}
|
||||
if(!in_array($id, $folder)){
|
||||
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){
|
||||
@ -25,7 +28,7 @@ class img {
|
||||
private static function getFolder($folder,$mask){
|
||||
$files = array();
|
||||
foreach (glob($folder.$mask) as $file) {
|
||||
$files[] = $file;}
|
||||
$files[] = basename($file);}
|
||||
return $files;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user