GetRoot('3'); // pobiera katalog główny $GetDir->GetHost('1'); // pobiera głownego hosta //echo "sys root: [".SYS_ROOT."]
"; //echo "oper root: [".OPER_ROOT."]
"; //echo "host: [".HTTP_HOST."]
"; $CrThb = New CreateThumbs(); $CrThb->getAllDirs(SYS_ROOT); class CreateThumbs { var $array_files; var $array_catalogues; function getAllDirs($path) { $dir = opendir($path); if ($path == SYS_ROOT) { // katalog glowny $actual_dir = $path; $catalogues_arr = $this->getDirs($actual_dir); $this->createDirLink($actual_dir, $catalogues_arr); $files_arr = $this->getFiles($actual_dir); $this->createPhotoLink($actual_dir, $files_arr); //$this->showTree($actual_dir, $files_arr); } while(false !== ($file = readdir($dir))) { if(is_dir($path.$file) && $file != '.' && $file != '..' && $file != '_thb' && $file != '_img') { $actual_dir = $path.$file.SYS_SEP; $catalogues_arr = $this->getDirs($actual_dir); $this->createDirLink($actual_dir, $catalogues_arr); $files_arr = $this->getFiles($actual_dir); $this->createPhotoLink($actual_dir, $files_arr); //$this->showTree($actual_dir, $files_arr); // przechodzi do nastepnego katalogu $this->getAllDirs($actual_dir); } } closedir($dir); } function getFiles($path) { unset($this->array_files); $dir = opendir($path); while(false !== ($file = readdir($dir))) { if(is_file($path.$file) && $file != '.' && $file != '..' && $file != 'index.html' && $file != 'm.php' && $file != 'info.txt' && $file != 'thumb.php') { $this->array_files[] = $file; } } closedir($dir); return $this->array_files; } function getDirs($path) { unset($this->array_catalogues); $dir = opendir($path); while(false !== ($file = readdir($dir))) { if(is_dir($path.$file) && $file != '.' && $file != '..' && $file != '_thb' && $file != '_img') { $this->array_catalogues[] = $file; } } closedir($dir); return $this->array_catalogues; } function createDirLink($actual_dir, $files_arr) { // otwieram plik do zapisu w biezacym katalogu $FileIndex = @fopen($actual_dir.'index.html', "w"); if(!flock($FileIndex, LOCK_EX)) { fclose($FileIndex); } else { flock($FileIndex, LOCK_EX); fputs($FileIndex, $this->htmlHeader()); if (SYS_ROOT <> '/') { $file_directory = substr(eregi_replace(SYS_ROOT, '', $actual_dir), 1); } else { $file_directory = substr($actual_dir, 1); } // upper directory if ($actual_dir <> SYS_ROOT) { //$typ_pliku = strtolower(substr($nazwa_pliku, -3)); $upper_dir_ = split('[\/]', $file_directory); $upper_dir_cnt = count($upper_dir_); $upper_dir = substr($file_directory, 0, strlen($file_directory)-(strlen($upper_dir_[$upper_dir_cnt-2])+1)); //echo 'upper_dir: '.$upper_dir."
"; $thumb = $this->makeThumb(null, null,'upper'); $http_link = "\"\""; fputs($FileIndex, $this->box($http_link,null,null)); } $cnt = count($files_arr); for($j = 0; $j < $cnt; $j++) { $thumb = $this->makeThumb(null, null,'dir'); $http_link = "\"{$files_arr[$j]}\""; fputs($FileIndex, $this->box($http_link,$files_arr[$j],null)); } //fputs($FileIndex, $this->htmlFooter()); flock($FileIndex, LOCK_UN); fclose($FileIndex); } } function createPhotoLink($actual_dir, $files_arr) { // otwieram plik do zapisu w biezacym katalogu $FileIndex = @fopen($actual_dir.'index.html', "a"); if(!flock($FileIndex, LOCK_EX)) { fclose($FileIndex); } else { flock($FileIndex, LOCK_EX); //fputs($FileIndex, $this->htmlHeader()); if (SYS_ROOT <> '/') { $file_directory = substr(eregi_replace(SYS_ROOT, '', $actual_dir), 1); } else { $file_directory = substr($actual_dir, 1); } //echo '---- actual_dir: ['.$actual_dir.'] SYS_ROOT: ['.SYS_ROOT.'] file_dir: ['.$file_directory.']
'; $cnt = count($files_arr); for($j = 0; $j < $cnt; $j++) { $wFile = $this->fileWeight($actual_dir.$files_arr[$j]); $thumb = $this->makeThumb($file_directory, $files_arr[$j],'file'); $http_link = "\"{$files_arr[$j]}\""; fputs($FileIndex, $this->box($http_link,$files_arr[$j],$wFile)); } fputs($FileIndex, $this->htmlFooter()); flock($FileIndex, LOCK_UN); fclose($FileIndex); } } function htmlHeader() { $hr = ""; $hr .= ""; $hr .= ""; $hr .= ""; $hr .= ""; $hr .= ""; $hr .= ""; $hr .= ""; return $hr; } function htmlFooter() { $fr = ""; $fr .= ""; return $fr; } function fileWeight($file) { $file_weight = filesize($file); if ($file_weight < 1000) {$file_weight = number_format(($file_weight), 1, ',', ' ').' B';} elseif ($file_weight >= 1000 && $file_weight < 1000000) {$file_weight = number_format(($file_weight / 1024), 1, ',', ' ').' KB';} elseif ($file_weight >= 1000000 && $file_weight < 1000000000) {$file_weight = number_format(($file_weight / (1024*1024)), 1, ',', ' ').' MB';} elseif ($file_weight >= 1000000000) {$file_weight = number_format(($file_weight / (1024*1024*1024)), 1, ',', ' ').' GB';} else {$file_weight = "";} return $file_weight; } function makeThumb($file_directory, $file, $type) { if ($type == 'file') { $ext_ = split('[.]', strtolower($file)); $ext_cnt = count($ext_); $ext = $ext_[$ext_cnt-1]; //echo 'file '.$file.' '.'ext: '.$ext.'
'; if ($ext == 'doc') {$min = "http://".HTTP_HOST.OPER_ROOT.IMG."/"."ico_word.gif";} elseif ($ext == 'pdf') {$min = "http://".HTTP_HOST.OPER_ROOT.IMG."/"."ico_pdf.gif";} elseif ($ext == 'ppt') {$min = "http://".HTTP_HOST.OPER_ROOT.IMG."/"."ico_ppt.gif";} elseif ($ext == 'ai') {$min = "http://".HTTP_HOST.OPER_ROOT.IMG."/"."ico_ai.gif";} elseif ($ext == 'tif') {$min = "http://".HTTP_HOST.OPER_ROOT.IMG."/"."ico_tiff.gif";} elseif ($ext == 'jpg') { if (file_exists(SYS_ROOT.$file_directory.THB."/".$file)) { $min = "http://".HTTP_HOST.OPER_ROOT.$file_directory.THB."/".$file; } else { $min = "http://".HTTP_HOST.OPER_ROOT.IMG."/"."ico_jpg.gif"; } } else {$min = "http://".HTTP_HOST.OPER_ROOT.IMG."/"."ico_empty.gif";} return $min; } elseif ($type == 'dir') { $min = "http://".HTTP_HOST.OPER_ROOT.IMG."/"."ico_dir.gif"; return $min; } elseif ($type == 'upper') { $min = "http://".HTTP_HOST.OPER_ROOT.IMG."/"."ico_upr.gif"; return $min; } } function box($http_link,$file,$wFile) { $ob = "
"; $ob .= "
{$http_link}
"; $ob .= "
{$file}
{$wFile}
"; $ob .= "
"; return $ob; } function showTree($actual_dir, $files_arr) { echo "actual_dir: ".$actual_dir."
"; if (count($files_arr) > 0) { foreach ($files_arr as $File) { echo $File."
"; } } } } class GetDirectory { function __construct() { define('IMG', '_img'); define('THB', '_thb'); $__sys_os = strtolower(substr(php_uname(),0,3)); if ($__sys_os == 'win') {$__sys_sep = '/';} else {$__sys_sep = '/';} define('SYS_SEP', $__sys_sep); define('HOST_SEP', '/'); } function GetRoot($type) { if ($type == '1') {$__root = $_SERVER['DOCUMENT_ROOT'];} if ($type == '2') {$__root = dirname(dirname(__FILE__));} if ($type == '3') {$__root = dirname(__FILE__);} if ($type == '4') {$__root = getcwd();} if (substr($__root, -1) <> SYS_SEP) {$__root .= SYS_SEP;} $__root = eregi_replace('[\/]',SYS_SEP, $__root); define('SYS_ROOT', $__root); $__oper = eregi_replace(eregi_replace('[\/]',SYS_SEP, $_SERVER['DOCUMENT_ROOT']), '', SYS_ROOT); if (substr($__oper, -1) <> SYS_SEP) {$__oper .= SYS_SEP;} define('OPER_ROOT', $__oper); } function GetHost($type) { if ($type == '1') {$__host = $_SERVER['HTTP_HOST'];} define('HTTP_HOST', $__host); } function __destruct() { } } ?>