<?php
// Set error reporting to all for testing
error_reporting(E_ALL);
class lcs_dir {
var $errorClass;
var $errorArray;
var $active;
var $path;
var $dirHandle;
var $arrayAll;
var $arrayDir;
var $arrayFile;
var $arrayOther;
var $numAll;
var $numDir;
var $numFile;
var $numOther;
function lcs_dir ($path, $read = '', $close = '') {
$this->_defineErrors();
$this->path = $path;
$this->active = 'n';
$this->open();
if ( $read == '' ) {
$this->read();
}
if ( $close == '' ) {
$this->close();
}
}
function open () {
if ( $this->dirHandle = @opendir($this->path) ) {
$this->active = 'y';
}
else {
$this->errorClass->error($this->errorArray['settings']['className'], $this->errorArray['open']['text'], __LINE__, $_SERVER['PHP_SELF'], $this->errorArray['open']['die']);
}
}
function read () {
if ( $this->active == 'n' ) {
return false;
}
else {
$this->arrayAll = array();
$this->arrayDir = array();
$this->arrayFile = array();
$this->arrayOther = array();
$this->numAll = 0;
$this->numDir = 0;
$this->numFile = 0;
$this->numOther = 0;
while ( false !== ( $dir = readdir($this->dirHandle) ) ) {
if ( $dir != "." && $dir != ".." && $dir != ".htaccess" ) {
$path_dir = $this->path.'/'.$dir;
if ( is_dir($path_dir) ) {
$this->arrayDir[$this->numDir] = $dir;
$this->numDir++;
}
elseif ( is_file($path_dir) ) {
$tempFile = explode('.', $dir);
if ( $tempFile['0'] == '' || @$tempFile['1'] == '' ) {
$this->arrayFile[$this->numFile]['name'] = $dir;
$this->arrayFile[$this->numFile]['ext'] = 'none';
}
else {
$tempNum = 0;
foreach ( $tempFile as $key => $value ) {
$tempNum = $key;
}
$this->arrayFile[$this->numFile]['name'] = $dir;
$this->arrayFile[$this->numFile]['ext'] = $tempFile[$tempNum];
}
unset($tempFile);
$this->numFile++;
}
else {
$this->arrayOther[$this->numOther] = $dir;
$this->numOther++;
}
}
}
sort($this->arrayDir);
sort($this->arrayFile);
sort($this->arrayOther);
foreach ( $this->arrayDir as $key => $value ) {
$this->arrayAll[$this->numAll]['name'] = $value;
$this->arrayAll[$this->numAll]['type'] = 'dir';
$this->numAll++;
}
foreach ( $this->arrayFile as $key => $value ) {
$this->arrayAll[$this->numAll]['name'] = $value['name'];
$this->arrayAll[$this->numAll]['ext'] = $value['ext'];
$this->arrayAll[$this->numAll]['type'] = 'file';
$this->numAll++;
}
foreach ( $this->arrayOther as $key => $value ) {
$this->arrayAll[$this->numAll]['name'] = $value;
$this->arrayAll[$this->numAll]['type'] = 'other';
$this->numAll++;
}
}
}
function close () {
closedir($this->dirHandle);
}
function _defineErrors() {
$this->errorClass = new lcs_error();
$this->errorArray = array();
$this->errorArray['settings'] = array();
$this->errorArray['settings']['className'] = 'Directory Class';
// Open Error
$this->errorArray['open'] = array();
$this->errorArray['open']['die'] = 'y';
$this->errorArray['open']['text'] = "The specified directory could not be opened. Please check that you have not made an error in your code.";
}
}
$lcs_loadedClass['dir.class.php'] = 1;
?>