ASDEVELOPMENT

galerija - class

Apr 7th, 2016
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?php
  2.  
  3. class Galerija{
  4.  
  5.     // atributi klase
  6.     public $path, $result;
  7.    
  8.     public function __construct(){
  9.         $this->path = DIRECTORY_SEPARATOR . '\images';
  10.     }
  11.  
  12.  
  13.     // Set funkcije
  14.     public function setPath($parametar){
  15.  
  16.  
  17.         if(substr($parametar, -1) === '/'){
  18.             $parametar = substr($parametar, -1);
  19.         }
  20.  
  21.         $this->path = $parametar;  
  22.        
  23.     }
  24.  
  25.  
  26.     // Get funkcije
  27.     public function GetDirectory($parametar){
  28.         return scandir($parametar);
  29.     }
  30.  
  31.  
  32.     public function GetImages($extensions = array('jpg', 'png', 'png')){
  33.         // uzimamo putanju do direktorija u kojem se nalaze slike
  34.         $images = $this->GetDirectory($this->path);
  35.  
  36.         foreach($images as $index => $image){
  37.  
  38.             $explode = explode('.', $image);
  39.             $extension = strtolower(end($explode));
  40.  
  41.             // Ukoliko se unutar niza (foldera) nalazi slika koja ne odgovara extenzijama (nisu/nije validna) koje su
  42.             // proslijeđene kao parametri, te slike (sliku) izbaci iz niza
  43.  
  44.             if(!in_array($extension, $extensions)){
  45.                 unset($images[$index]);
  46.             }
  47.  
  48.             else {
  49.                 $this->result[$index] = array(
  50.                     'full'  => $this->path . DIRECTORY_SEPARATOR . $image
  51.                 );
  52.             }
  53.  
  54.         }
  55.  
  56.         return (count($this->result)) ? $this->result : false;
  57.     }
  58.  
  59.  
  60.     // Info funkcija
  61.     public function Info(){
  62.         echo $this->path;
  63.     }
  64. }
Add Comment
Please, Sign In to add comment