upload func in img implemented
This commit is contained in:
parent
7e3f8b5769
commit
3c0d87dbce
76
img/img.php
76
img/img.php
@ -1,41 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace SYSTEM\IMG;
|
||||
|
||||
class img {
|
||||
class img {
|
||||
|
||||
private static $imgfolders = array(); //only strings! (catname => array(2.path 3.mask))*
|
||||
|
||||
public static function registerFolder($path,$cat,$mask){
|
||||
self::$imgfolders[$cat] = array($path,$mask);}
|
||||
|
||||
public static function get($cat = null,$id = null,$returnasjson = false){
|
||||
if(!$cat){
|
||||
return $returnasjson ? \SYSTEM\LOG\JsonResult::toString(self::$imgfolders) : 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]);
|
||||
if($id == null){
|
||||
return $returnasjson ? \SYSTEM\LOG\JsonResult::toString($folder) : $folder;}
|
||||
|
||||
if(!in_array($id, $folder)){
|
||||
throw new \SYSTEM\LOG\ERROR("No matching ID '".$id."' found.");}
|
||||
|
||||
\SYSTEM\HEADER::PNG();
|
||||
return file_get_contents(self::$imgfolders[$cat][0].$id);
|
||||
|
||||
public static function registerFolder($path, $cat, $mask) {
|
||||
self::$imgfolders[$cat] = array($path, $mask);
|
||||
}
|
||||
|
||||
public static function put($cat,$id,$contents){
|
||||
throw new \SYSTEM\LOG\ERROR("not implemented");}
|
||||
|
||||
private static function getFolder($folder,$mask){
|
||||
|
||||
public static function get($cat = null, $id = null, $returnasjson = false) {
|
||||
if (!$cat) {
|
||||
return $returnasjson ? \SYSTEM\LOG\JsonResult::toString(self::$imgfolders) : 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]);
|
||||
if ($id == null) {
|
||||
return $returnasjson ? \SYSTEM\LOG\JsonResult::toString($folder) : $folder;
|
||||
}
|
||||
|
||||
if (!in_array($id, $folder)) {
|
||||
throw new \SYSTEM\LOG\ERROR("No matching ID '" . $id . "' found.");
|
||||
}
|
||||
|
||||
\SYSTEM\HEADER::PNG();
|
||||
return file_get_contents(self::$imgfolders[$cat][0] . $id);
|
||||
}
|
||||
|
||||
public static function put($cat, $id, $contents) {
|
||||
if (!array_key_exists($cat, self::$imgfolders)) {
|
||||
throw new \SYSTEM\LOG\ERROR("No matching Cat '" . $cat . "' found.");}
|
||||
return move_uploaded_file($contents, self::$imgfolders[$cat][0].$id);
|
||||
}
|
||||
|
||||
private static function getFolder($folder, $mask) {
|
||||
$files = array();
|
||||
foreach (glob($folder.$mask) as $file) {
|
||||
$files[] = basename($file);}
|
||||
foreach (glob($folder . $mask) as $file) {
|
||||
$files[] = basename($file);
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
public static function getURL($cat,$id=null){
|
||||
return \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEURL).'api.php?call=img&cat='.$cat.'&id='.$id;}
|
||||
|
||||
|
||||
public static function getURL($cat, $id = null) {
|
||||
return \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEURL) . 'api.php?call=img&cat=' . $cat . '&id=' . $id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,23 +2,30 @@
|
||||
namespace SYSTEM\SAI;
|
||||
|
||||
class saimod_sys_img extends \SYSTEM\SAI\SaiModule {
|
||||
public static function sai_mod__SYSTEM_SAI_saimod_sys_img_action_upload($cat){
|
||||
if(!\SYSTEM\IMG\img::put($cat, basename($_FILES['datei']['name']) , $_FILES['datei']['tmp_name'])){
|
||||
throw new \SYSTEM\LOG\ERROR("upload problem");}
|
||||
|
||||
throw new \SYSTEM\LOG\ERROR("upload finished sucessful");
|
||||
}
|
||||
public static function sai_mod__SYSTEM_SAI_saimod_sys_img(){
|
||||
//tt
|
||||
$result = '';
|
||||
$img_folders = \SYSTEM\IMG\img::get();
|
||||
$result .= '<form action="upload.php" method="post" enctype="multipart/form-data">';
|
||||
$img_folders = \SYSTEM\IMG\img::get();
|
||||
foreach($img_folders as $name=>$folder){
|
||||
$cat = \SYSTEM\IMG\img::get($name);
|
||||
$result .= "<h3>".$name."</h3>";
|
||||
|
||||
$result .= '<input type="file" name="datei"><br>
|
||||
<input type="submit" class="btn" value="Hochladen">';
|
||||
$result .= '<form action="'.\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_SAI_CONFIG_BASEURL).'sai_mod=.SYSTEM.SAI.saimod_sys_img&action=upload&cat='.$name.'" method="post" enctype="multipart/form-data">';
|
||||
$result .= '<input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
|
||||
<input type="file" name="datei"><br>
|
||||
<input type="submit" class="btn" value="Hochladen">';
|
||||
$result .= "</form>";
|
||||
|
||||
foreach($cat as $img){
|
||||
//$result .= '<img src="api.php?call=img&cat='.$name.'&id='.$img.'" alt="" />';
|
||||
$result .= '<li><a href="api.php?call=img&cat='.$name.'&id='.$img.'">'.$img.'</a></li>';
|
||||
}
|
||||
}
|
||||
$result .= "</form>";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user