Location: PHPKode > scripts > DigiOz Indexer > digioz-indexer/clsIndexer.php
<?php

////////////////////////////////////////////////////////////////// 
// Title:		DigiOz Directory Indexer Class
// File Name:	clsIndexer.php
// Description:	The purpose of this PHP Class is to obtain a list of files
//			and directories in a specified directory, sort them, 
//			determine if its a file or directory and return a 2-D Array
//			to the calling function. 
// PHP Version:	Works on PHP 4 , but obtimized for PHP 5
// Created On:	08-14-07
// Updated:		11-28-07
// Author:      Pedram Soheil
// Website:     http://www.digioz.com
////////////////////////////////////////////////////////////////// 

class indexer 
{
	var $path;
	var $filename;
	var $filename_sorted;
	
	/*************************************/
	/*		Class Constructor
	/*************************************/
	
	function indexer() 
	{
		$this->path = "";
	}
	
	/*************************************/
	/*		Array Sort Function
	/*************************************/
	
	function csort($array, $order, $column)
	{
		$i=0;

		for($i=0; $i<count($array); $i++)
		{
			$sortarr[]=$array[$i][$column];
		}
      
		if($order == "SORT_ASC")
		{
			array_multisort($sortarr, SORT_ASC, $array);
		}
		else
		{
			array_multisort($sortarr, SORT_DESC, $array);
		}

		return($array);
	}
	
	/*************************************/
	/*		List Directory Function
	/*************************************/
	function listDir($path, $sortType, $columnIndex)
	{
		$i=0;
		$this->path = $path;
		$handle = opendir($this->path); 

		while (false !==($file = readdir($handle)))
		{ 
			if ($file != "." && $file != "..") 
			{
				$this->filename[$i][1] = $file;
				$this->filename[$i][2] = filemtime($path.$file);
				$this->filename[$i][3] = round(filesize($path.$file)/1024);
				
				if (is_file($path.$file))
				{
					$this->filename[$i][4] = "FILE";
				}
				elseif (is_dir($path.$file))
				{
					$this->filename[$i][4] = "DIR";
				}
				else
				{
					$this->filename[$i][4] = "";
				}
				++$i;
			}
		}
		$i = 0;
		
		if ($columnIndex==3)
		{
			$sortType=" SORT_NUMERIC ,$sortType";
		}
		
		$this->filename_sorted = $this->csort($this->filename, $sortType, $columnIndex);
		closedir($handle);
		return $this->filename_sorted;
	}	
}

?>
Return current item: DigiOz Indexer