Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Incorporating OOP in existing PHP
- class ImageData {
- private $count;
- private $dirArray;
- public function __construct() {
- $count = 0;
- $dir = "panos/thumbs";
- $dirCon = opendir($dir);
- while ($name = readdir($dirCon)){
- if (strtolower(substr($name, -3)) == "jpg"){
- $dirArray[]= $name;
- }
- }
- sort($dirArray);
- $count= count($dirArray);
- closedir($dirCon);
- }
- public function getCount(){
- return $this->count;
- }
- public function getArray(){
- return $this->dirArray;
- }
- }
- $imageData = new ImageData();
- $count = $imageData->getCount();
- $data = $imageData->getArray();
- class ImageData {
- protected $count = 0;
- protected $dir = null;
- protected $dirArray = null;
- public function __construct( $dir = 'panos/thumbs') {
- $this->dir = $dir;
- }
- public function getCount(){
- if ( is_array($this->dirArray) ){
- $this->initialize();
- }
- return $this->count;
- }
- public function getArray(){
- if ( is_array($this->dirArray) ){
- $this->initialize();
- }
- return $this->dirArray;
- }
- protected function initialize(){
- $this->dirArray = $this->findImages();
- sort($this->dirArray);
- $this->count = count($dirArray);
- }
- protected function findImages( $extensions = array('jpg') ){
- $files = array();
- $dirCon = opendir($this->dir);
- while ($name = readdir($dirCon)){
- $current = strtolower(substr($foo, strrpos($foo, '.')+1));
- if ( in_array( $current, $extensions ) ){
- $files[] = $name;
- }
- }
- closedir($dirCon);
- return $files
- }
- }
Add Comment
Please, Sign In to add comment