Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Galerija{
- // atributi klase
- public $path, $result;
- public function __construct(){
- $this->path = DIRECTORY_SEPARATOR . '\images';
- }
- // Set funkcije
- public function setPath($parametar){
- if(substr($parametar, -1) === '/'){
- $parametar = substr($parametar, -1);
- }
- $this->path = $parametar;
- }
- // Get funkcije
- public function GetDirectory($parametar){
- return scandir($parametar);
- }
- public function GetImages($extensions = array('jpg', 'png', 'png')){
- // uzimamo putanju do direktorija u kojem se nalaze slike
- $images = $this->GetDirectory($this->path);
- foreach($images as $index => $image){
- $explode = explode('.', $image);
- $extension = strtolower(end($explode));
- // Ukoliko se unutar niza (foldera) nalazi slika koja ne odgovara extenzijama (nisu/nije validna) koje su
- // proslijeđene kao parametri, te slike (sliku) izbaci iz niza
- if(!in_array($extension, $extensions)){
- unset($images[$index]);
- }
- else {
- $this->result[$index] = array(
- 'full' => $this->path . DIRECTORY_SEPARATOR . $image
- );
- }
- }
- return (count($this->result)) ? $this->result : false;
- }
- // Info funkcija
- public function Info(){
- echo $this->path;
- }
- }
Add Comment
Please, Sign In to add comment