IT rekvalifikace s garancí práce. Seniorní programátoři vydělávají až 160 000 Kč/měsíc a rekvalifikace je prvním krokem. Zjisti, jak na to!
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.

HfalkW

galerie

php

class Galerie {
    private $cols = 5;
    private $folder;
    private $images = array();
    private $ignore = array(".","..","Thumbs.db","DS_Store",".htaccess");
    private $excluded = array();
    private $output;
 
    public function __construct($folder) {
        $this->folder = $folder;
    }
    public function setFolder($folder) {
        $this->folder= $folder;
    }
    private function scanDirectory() {
        if(is_dir($this->folder)) {
            foreach(scandir($this->folder) as $key=>$value) {
                if(in_array($value, $this->ignore)) {
                    unset($key);
                    $this->excluded[] = $value;
                } else {
                    $this->images[] = $value;
                }
            }
        } else {
            throw new Exception("The Folder has not valid.", 1);
            
        }
    }
    public function getFolder() {
        return $this->folder;
    }
 
    public function addIgnore($ignore) {
        $this->ignore[] = $ignore;
    }
    public function getIgnore() {
        return $this->ignore;
    }
    public function getImages() {
        try{
        $this->scanDirectory();
        if(is_scalar($this->images)) 
                throw new Exception("Program error: In the folder there are not no pictures.", 1);
        return $this->images;
        } catch (Exception $e) {
            echo "Program error: " . $e->getMessage();
        }
    }
 
    public function showImages() {
        try {
            $this->scanDirectory();
            if(is_scalar($this->images)) 
                throw new Exception("Program error: In the folder there aren't no pictures.", 1);
            $counter = 0;
            $this->output .= "<TABLE ID=\"galerie\"><TR>";
            foreach($this->images as $img) {
                $counter++;
                $this->output .= "<TD><a href=\"".$this->folder."/".$img."\"><img src=".$this->folder."/nahledy/".$img." width=\"120\" height=\"120\" border=\"0\"></TD>";
                if(!($counter % $this->cols))
                    $this->output .= "</TR><TR>";
            }
            $this->output .= "</TR></TABLE>";
            return $this->output;
 
        } catch (Exception $e){
            echo "Program error: " . $e->getMessage();
        }
    }
}
 
$galerie = new Galerie("./tapety");
$galerie->addIgnore("nahledy");
echo $galerie->showImages();
?>
<style>
table tr td img {
    border: 1px solid black;
    padding: 3px;
    box-shadow: gray 2px 3px 10px;
    margin: 3px;
}
<style>


Neformátovaný

Přidáno: 28.1.2014
Expirace: Neuvedeno

Avatar
Autor: H*falk*W
Aktivity